How does one debug complex constexpr code? I assume there's no printf.
It'd be really cool if it supported some kind of interpolation, like Jinja templates, so it could generate dynamic page templates at compile time.
How does one debug complex constexpr code? I assume there's no printf.
It'd be really cool if it supported some kind of interpolation, like Jinja templates, so it could generate dynamic page templates at compile time.
template <typename T, typename ...Ts>
void show_types()
{ static_assert((T*)nullptr, "Type log"); }
int main()
{
show_types<int, float, bool>();
}
When trying to compile this, using something like `g++ show-type.cpp`, you'll get this output: show-type.cpp: In instantiation of ‘void show_types() [with T = int; Ts = {float, bool}]’:
show-type.cpp:7:32: required from here
show-type.cpp:3:3: error: static assertion failed: Type log
{ static_assert((T*)nullptr, "Type log"); }
The same can be done for non-type template args, of course.T::asdfasdf();
Although I might start using yours.
#define constexpr
Which makes all the code plain code that executes at runtime, then you can put your couts and use your debuggers.
Its orders of magnitude simpler than dealing with template meta-programming.
constexpr_printf is the feature I want most of all. There is actually a patch for gcc that implements this.
I dont know how Jinja works, but the idea here is you do templating at runtime, but your templates get compiled down to a tree like DS at compiletime
I decided to use a runtime DS to allow things like splicing and looping templates etc.
It's also possible to make the runtime render the compiled time DS directly, which should be even faster if your requirements are simple enough