One size fits all

Today I learned: C++ does not have a single one-size-fits-all way to bring an arbitrary name into the current scope. It has three:

using a::b; works anywhere but only for certain names

using b = a::b; works anywhere but only for types, and sometimes you have to template it!!

namespace b = a::b; only works at namespace scope and only for namespaces

I never realized that was an issue before. Now I have some code that looks like this:
35
36
37
38
39
40
41
42
43
44
45
using Magnum::Math::operator""_degf;
using Magnum::Matrix3;
using Magnum::Matrix4;
using Magnum::Renderer;
using BlendFunction = Magnum::Renderer::BlendFunction;
using BlendEquation = Magnum::Renderer::BlendEquation;
namespace SceneGraph = Magnum::SceneGraph;
namespace Text = Magnum::Text;
using Magnum::Vector2;
using Magnum::Vector2i;
using Magnum::Vector3;
Hopefully it gets fixed in C++17 :/
Last edited on
I just use macros. *snicker*
That only brings them into the global scope, whereas I want local scope ;)
You can do that. There's #undef and #pragma push_macro and #pragma pop_macro.
That's no longer a single line per name.
You are too hard to please.
Look, the system you're suggesting is quite literally worse than what I outlined in the first post. I can deal with the current system. I'm not going to do weird nonsense with macros just to avoid the current system.
Last edited on
It's only worse if you're a reasonable person. If you were insane, like me, you'd see how M4->C has as much expressive power as C++.
Hopefully it gets fixed in C++17 :/

I don't think there are any proposals to change namespace aliases, type aliases, or using-declarations (other than the just voted-in rewording of inheriting constructors)

If you have a concrete idea (the motivating example is nice, but what syntax would you like to see, precisely?), float it on std-proposals as outlined in https://isocpp.org/std/submit-a-proposal .
M4->C has as much expressive power as
M4? Just the mention of it gives me a headache.

Now I have some code that looks like this:


What's wrong with that code? You don't like the way it looks? I also don't see the issue with having 3, well really 2 ways. The distinction for namespaces should exist IMO. Then the only thing that really doesn't work is function aliasing using swapo = std::swap. You just use the first "using" if you don't want to change the name and the other "using" if you do.

What is BlendFunction? An enum? You should be able to use using Magnum::Renderer::BlendFunction;.


1
2
using Magnum::Matrix3; // to use in current scope
using Matrix3x3 = Magnum::Matrix3; // to give an alias of something in current scope 


I don't see any way this can be merged into one, unless you just get rid of the first option. Then people will be complaining about how they have to retype the same name twice.
Last edited on
@goosestuf: ideally it shouldn't matter what something is. There should be one syntax for bringing a name into the current scope, regardless of what that name refers to. IMO using a::b; and using c = a::b; syntax should work for all things and in all scopes. Templates shouldn't complicate things.

It's just a personal gripe.
Topic archived. No new replies allowed.