Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inspect C++ template instantiation

Tags:

c++

templates

Is there some utility which would allow me to inspect template instantiation? my compiler is g++ or Intel.

Specific points I would like:

  • Step by step instantiation.
  • Instantiation backtrace (can hack this by crashing compiler. Better method?)
  • Inspection of template parameters.

@gf helpd me with simple type printing, C++ template name pretty print.

However I am getting into boost phoenix and template level makes it very hard to understand what is going on and I would like intelligent solution

also, if you have some techniques inspecting template instantiation, can you please share them.

Thanks

like image 471
Anycorn Avatar asked May 22 '10 04:05

Anycorn


1 Answers

With templates we simply don't have clean output facilities and there are no compilers i know of that allow you to directly view template instantiations. The closest i found regarding metaprogram debugging was a paper on Templight.

For now the best utilities seem to be:

  • static asserts & concept checks (clearly assert your assumptions)
  • the mentioned instantiation backtraces (e.g. by using static asserts)
  • letting instantiations generate warnings (boost::mpl::print might do it)
  • a tracer, a custom class that gets passed as a template argument and is used to emit runtime output (introduced by C++ Templates - The Complete Guide)
like image 169
Georg Fritzsche Avatar answered Oct 04 '22 22:10

Georg Fritzsche