Anyone who works with generator programming or metaprogramming templates in one form or another is experiencing difficulties such as unexpectedly long compilation periods, large executables, deeply embedded compiler error messages, or type names that fill all screens.
A recent unsuccessful example is the "unexpected" creation of unused functions . Just for motivation, today I had another "unexpected" series of events, where:
- type, say
T , is tested by std::is_empty ; - SFINAE implementation for this (if not built-in), deduces another type, for example
D , from T ; - perhaps creating an implicit assignment operator for
D creates an instance of universal assignment T (user-defined), - due to
std::enable_if , this statement creates an instance of std::is_assignable <M, T> , where M is a member or base type of T , and an instance of the same class template as T ; - in the end, the type
TR is created on T , which requires std::is_empty <T> ; at this moment I get an error so that some type is incomplete.
I could easily fix this with some TR specialization, because std::is_empty is not needed in this particular case. Easy means about two hours to analyze error messages first. The funny thing is that all this was discovered when I deleted the unused unconditional assignment operator from another place (the βdistantβ base class T ). The patch also speeds up compilation, but I would not investigate if it was wrong.
In the past, I have seen that compilation time is reduced, for example. from 2 minutes to 10 seconds with small or large spots, suitable both randomly and with little imagination.
Question : are there any systematic methods or tools to control what happens while waiting for our template code to be compiled, which will help us improve the code even if it works, similar to how we debug programs at runtime?
The only (or best) tool I've seen is Templight , which works with clang and requires a patch for the compiler. It looks cool from Meeting C ++ slides , but before I try, I will be grateful for any relevant ideas.
Other questions / resources that I found, such as
but quite outdated.
source share