Please see this example . An attempt to use constexprto obtain an estimate of compilation time would be extremely difficult, if not impossible.
However, when a function is called, all arguments are known at compile time. Theoretically (if there is some optimization attribute?), The Compiler can pause parsing, create a small program using a function, compile it, run it and get the result to create a char constant that will be used mainly to compile the program.
I understand that one of the problems can be, for example, cross-compilation: you can run the program only from the compiler, if the compiler can create a program that can run on a machine that builds. But this does not seem impossible to overcome.
There is no doubt: I am not the first to think about it. But I tried to search, and I could find things constexprand template. Is there any plan for implementing such a function in any compiler in the future? This function can also be rephrased as: Give the opportunity to write a C ++ program in your C ++ source, which the compiler can compile and run on demand to create a constant.
source
share