Re:C++17 constexpr everything, or as much as the compiler can
by tambre on Thursday December 28, 2017 @10:59AM
(#16022720)
> A constexpr is a constant that is evaluated from a code at compile time, [...]
It's rather a constant expression, which is quite a bit more than a mere constant.
> [...] which is essentially just macros. Right?
Macros are basically just text replacement. You can't write a macro and expect most compilers to execute the expressions and code inside the macro at compile-time. Some compilers may still to do that, but it's not very common for more complicated stuff. With constexpr you get a guarantee that the expression can be evaluated at compile-time and it gives quite a good hint to the optimizer to spend more time optimizing that portion of the code.
Re:C++17 constexpr everything, or as much as the compiler can
by hzhou321 on Friday December 29, 2017 @02:54AM
(#16028298)
With a macro, you get guarantee of compile time evaluation, as well as compile time independent literal syntax double check. And you can do better than hint. You can double check the results explicitly. Since it's compile time evaluation, optimization is out of context.
Re:C++17 constexpr everything, or as much as the compiler can
by tambre on Saturday December 30, 2017 @10:08AM
(#16035534)
If you call searching and text replacement evaluation, then sure.
Re:C++17 constexpr everything, or as much as the compiler can
by hzhou321 on Saturday December 30, 2017 @07:29PM
(#16038549)
It can be more than that.
Re:C++17 constexpr everything, or as much as the compiler can
by krylon on Thursday December 28, 2017 @12:24PM
(#16023355)
> a general meta layer preprocessor such as MyDef
I did not even know such a thing existed. Thank you!
Re:C++17 constexpr everything, or as much as the compiler can
by hzhou321 on Friday December 29, 2017 @03:02AM
(#16028319)
I didn't find any, so I rolled my own 10 years ago. Most of its features are suited toward very limited users. E.g. it doesn't really support macro evaluation from arbitrary language, only from Perl currently (but general for any target language). However,to support macro evaluation from arbitrary language seems trivial. It'll be just like gcc pulling different compiler together.
A constexpr is a constant that is evaluated from a code at compile time, which is essentially just macros. Right?
A general preprocessor that just do language agnostic code manipulations are not difficult but rather useful. Much complicated syntax sugar I see in the recent language development become unnecessary if a general preprocessor is in place (where syntactic sugar belong). I wonder why it is often not used.