Generate C++ code where templates have been expanded

后端 未结 3 1974
野的像风
野的像风 2021-01-06 09:34

I was wondering if there is a way to use a C++ compiler to just produce C++ code where all templates have been expanded to the instantiations that are required by the progra

相关标签:
3条回答
  • 2021-01-06 10:03

    Templates are part of the language, not some pre-processor pass - they are processed by the compiler, just like other code.

    There is no way to do this in Visual Studio 2012 (Property -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocess to a File - won't give you expanded templates).

    The g++ has a bunch of debug options. I would try -fdump-class-hierarchy (not tested).

    0 讨论(0)
  • 2021-01-06 10:07

    One way would be to compile your program in debug and then dump the symbols. All the compiled templates must have their symbol defined.

    g++ -g foo.cpp -o foo.o
    

    Ofcourse you would missed inlined functions, but this can be suppressed with

    g++ -g -fno-inline-functions foo.cpp -o foo.o
    

    To get the symbols use:

    objdump -t --demangle a.out
    
    0 讨论(0)
  • 2021-01-06 10:08

    I think "Templator" might help: Demo at CppCon2015, Slides

    0 讨论(0)
提交回复
热议问题