-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
C++ 11+ allows for the definition of user-defined type aliases with using as a replacement for doing the same with typedef
Typical Structure for Using vs Typedef :
using alias = ExistingType;
typedef ExistingType alias; using can be used in place of typedef to define aliases
Some examples of using and equivalent typedef alternatives
using Vec = vector<int>;
typedef vector<int> Vec;
using FunctionPointer = void(*)(int, double);
typedef void(*FunctionPointer)(int, double);
using charArray = char[10];
typedef char charArray[10]; using can also be used to define aliases with templated parameters, which typedef cannot do as simply
example:
template<typename T>
using Vec = std::vector<T>;
Vec<int> myIntegerVec;
//there is no equivalent way to do this with typedef, bellow code is not legal
template<typename X>
typedef vector<X> Vec; // this is not legal and would not work
//to accomplish this with typedef you would have to use a struct
template<typename Y>
struct Vec{
typedef std::vector<Y> type;
};
Vec<int>::type myIntegerVec; This manner of creating user-defined aliases with using is not currently supported by nameCollector, currently nameCollector does not collect any alias names defined in this manner and skips over them.
Metadata
Metadata
Assignees
Labels
No labels