Debug metaprograms

Is there a way to check, step by step, what is happening in let say template? I mean, how is it created in stages, etc.?

In the book I mentioned here ,

I found (2 minutes ago) a rather interesting example of how binary code can be implemented as a metafunction.

template <unsigned long N> struct binary { static unsigned const value = binary<N/10>::value << 1 // prepend higher bits | N%10; // to lowest bit }; template <> // specialization struct binary<0> // terminates recursion { static unsigned const value = 0; }; 

and I think that it would be very useful to see step by step what was done during the creation of this template. Thank you for your responses.

+6
c ++ debugging metaprogramming
source share
1 answer

The best I've seen so far is the Templight research paper, but I am not aware of any public implementation.

You can help yourself though by using descriptive static (i.e. compilation time) - see, for example, Boosts static assert or MPLs claims . In some cases, this can help provoke a compilation error (for example, using static statements) to get a trace of the creation of a template from the compiler.
There is also nothing to prevent you from displaying the results of testing a meta-function for testing.

0
source share

All Articles