Clearly, type aliases and templated type aliases are semantically equivalent to typedefs and an extension of typedefs to support template. How come new syntax with the using
keyword was created for these instead of using typedefs for the first and some syntax extension with the word typedef
.
NOTE: This is not a clone of the "difference between using and typedef" question. I know that using
gives the advantage of defining a family of typedef
s. What I am asking is why did the standard people decide on having this extension use the using
keyword instead of the typedef
keyword. This seems like it just adds confusion in the language.
Best Answer
Here is what Bjarne Stroustrup says about why they introduced
using
instead of extendingtypedef
:He also claims that he likes this syntax also more for usual typedefs:
He is quite correct here, this seems very clean. In contrast a typedef would be extremely convoluted with the name being somewhere in the middle:
Here is an explanation (see page 4) from their proposal that is even more in-depth:
So he has basically two points here:
using
template becomes a family of types, not a type, sotypedef
is "wrong"using
can be read almost as an english sentence