C++ see template instantiations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tassos Souris
    New Member
    • Aug 2008
    • 152

    C++ see template instantiations

    Hi!

    Is there a way in either Visual Studio 2010 or g++ (any version) to see what classes it instantiates and their code? For example to see if i avoid code bloat when i explicitly instantiate a template for certain types.

    Thanks!
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I'm not sure what you are asking.

    As you are probably aware, the compiler makes a copy of a template and substitutes the types you specify. So if 35 types can use the same logic you need write one function (the template) rather than coding the 35 implementations yourself.

    Explicit specializations just tell the compiler not to use the template for the type you specify. This usually means the template logic can't be used for that type so you have written a function yourself for that type.

    So where's the bloat?

    Usually bloat refers to constructors, destructors and various member functions used to implement OOP. With today's large memory machines I don't hear about bloat much.

    Please give me a little more to go on.

    Comment

    • Tassos Souris
      New Member
      • Aug 2008
      • 152

      #3
      See it as a general question about IDEs.. for example i make a simple main function where i use a std::vector<int > and maybe a std::list<std:: string>.. where can i see that the compiler has generated those instantiations (not necessary see their code but e.g. symbols for their names, functions instantiated etc)... the only reason that it might be helpful to me is to see "in action" all the instantiation rules and specializations and stuff and stuff since i am now learning them

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Usually, I just use the debugger and step into the code. You will be able to step into the template where you can see the parameter type. Then you can step through the template.

        Reading MSDN is more helpful than using the debugger.

        Aceess to a good C++ textbook is better than using MSDN.

        Comment

        Working...