Search code examples
c++templatescompilationtypedef

Is typedef resolved at compile time in c++?


I'm writing a c++ code where I need high performance. But I also want my code to be readable so I'm using typedef but I am not sure if this will slow my program down. Also my typedef is used in class with template so I am not sure if that will change anything or not. This is the code:

template<class T>
class A {
   typedef std::vector<T> v;

};

Solution

  • A typedef is just something to make an alias. The compiler doesn't care about these internally and it has no impact on the generated code.

    The final (non-debug) executable will make no reference to either of these things, it'll all be baked out as machine code.