Skip to content

C++ 11+ Type alias definition with 'using' not supported #33

@sophia-gh

Description

@sophia-gh

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions