0

How can I see the temporary code generated by template meta-programming (abreviated as "TMP") in c++ by g++ or by visual studio? It is my understanding that when using TMP, the compiler generates "the implied" c++ code. This would put it somewhere around the parser and before the assembler, so it should (I think) be "readable" (although verbose). Is there a way to do this directly in my own source code?

I am trying to understand TMP. I have been reading through the wikibooks article on the topic. I believe this is also sometimes more generically called [generic programming] and is used extensively in both [stl] and [boost].

Currently, I am using G++ on GNU/Linux, and would much prefer help related to that. I believe this is the correct SE site to post this because the Tour states that good questions may involve "Software development tools", "Specific programming problems" and "Coding techniques", and I am not asking for a specific tool recommendation.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
MathFromScratch
  • 133
  • 1
  • 5
  • Clang provides way to display the ast of a TU, and there are tools to help to visualize them (as [Clang-ast-viewer](https://github.com/CAST-projects/Clang-ast-viewer)). – Jarod42 Jun 10 '16 at 17:40
  • 1
    Related to [debugging-template-instantiations](http://stackoverflow.com/questions/7325910/debugging-template-instantiations) – Jarod42 Jun 10 '16 at 17:42
  • Probably not. The standard doesn't prescribe any particular method of implementing templates. It is possible and indeed likely that the implied code generated by the compiler when doing template expansion looks nothing like C++. It is much more economical to expand templates and generate machine code right from the AST. [This question may have been asked before](https://www.google.com/search?q=g%2B%2B+dump+template+expansion). – n. m. could be an AI Jun 10 '16 at 17:48
  • 1
    You might like http://metashell.org/ – Jan Korous Jun 10 '16 at 17:50

0 Answers0