Create C ++ code where the templates have been extended

I was wondering if there is a way to use the C ++ compiler to create C ++ code, where all the templates have been expanded to the instances required by the program. This code should exist at some point in the compilation process, although apparently it is apparently not in ASCII form by default, but in my opinion, it should not be too difficult to convert it back to readable C ++ code.

EDIT: I'm more interested in the solution that will generate the actual C ++ code (which at least compiles and ideally also reads), and not just an overview of the classes and functions that are created. This seems like a useful feature to simplify reading complex template code (for example, for debugging) or if the code needs to be processed by software other than the regular C ++ compiler, which may (completely) not support templates.

+4
source share
3 answers

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

Visual Studio 2012 ( → → C/++ → → - ).

g++ . -fdump-class-hierarchy ( ).

+3

, "Templator" : CppCon2015,

+2

, . .

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

, ,

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

:

objdump -t --demangle a.out
+1

Source: https://habr.com/ru/post/1612396/


All Articles