When dealing with macros we can use (for gcc -dM) option to let pre-compiler unravel the macro definition into the c++ source. I am looking for a tool, better yet compiler option to do the same with templates (even in the limited fashion). If I inherited the code with multilayered templates mixed with multiple inheritance that would be very help? Especially that machine has to know exactly what is the state of the code after template interpretation. I would not even complained about the mangled names , as long as the flatten structure of the code is exposed.
-
1There is no comparison between templates and macros. What is the problem you're trying to solve. No, not the one about "pre-compiling templates". It's the problem that you believe whose solution is to obtain "pre-compiled templates", so you're asking about the solution, instead of about the real problem. – Sam Varshavchik Jul 28 '19 at 23:49
-
2Maybe "explicit instantiation" is useful for your situation? – Kerrek SB Jul 28 '19 at 23:54
-
https://cppinsights.io/ might help. – Jarod42 Jul 29 '19 at 00:04
-
@SamVarshavchik I try to understand the code someone left for me to fix and it looks like old "goto" spiced PL/1 with all inheritance and templates overlayed upon; – kris2k Aug 02 '19 at 01:45
1 Answers
You can't really do that.
Macros are super simple. They're little more than text replacement.
However, templates are a part of the semantic, hypothetical, theoretical, academic, unknowable, esoteric, satanic, ethereal juice that powers your hobby.
They exist only in the space between source code and program.
The void, between life and death.
There is no textual representation. There is only a feeling. A set of thoughts. An instinct that your compiler holds, from the time that you feed it words, to the time that it spits out actions.
Okay, sure, in theory there's some human-readable format in which a compiler could dump template instantiations in all their glory, but let's be honest: the easiest way for it to do that is to spit out the C++ that you gave it in the first place.
So, yeah, no.
That being said, if you really want a headache, learn to use the LLVM backend API.

- 378,754
- 76
- 643
- 1,055
-
LLVM that is something I have to look into, thank you; I have asked this question because I have seen proprietary tool which was doing more or less what I am looking for (maybe: https://blogs.grammatech.com/separate-compilation-templates ) , also I guess I should ask about debugging - https://stackoverflow.com/questions/7325910/debugging-template-instantiations; – kris2k Aug 02 '19 at 01:47