6 ms·
> compile-time function evaluation Sorry, potentially stupid question incoming: I thought this was pretty standard for c++ optimizing compilers. What makes D's
by 542458 8y ago
> compile-time function evaluation
Sorry, potentially stupid question incoming: I thought this was pretty standard for c++ optimizing compilers. What makes D's version of this special?
- VHRanger 8y agoIt means you can run compile time programs without resorting to crazy template metaprogramming
- zamalek 8y agoC++ now has constexpr, so that pro is now shared by both C++ and D, somewhat (ignoring templates, D is still more versatile). That being said, C++ template metaprogramming can be pretty elegant[1] (there was a video where she describes the template functional style, but it seems to have been deleted). [1]: https://github.com/hanickadot/compile-time-regular-expressions https://github.com/hanickadot/compile-time-regular-expressio...
- WalterBright 8y agoconstexpr accretes more power with every iteration, but it's still got a ways to go: https://en.cppreference.com/w/cpp/language/constexpr https://en.cppreference.com/w/cpp/language/constexpr https://dlang.org/spec/function.html#interpretation https://dlang.org/spec/function.html#interpretation
- int_19h 8y agoIt's not an optimization in this case - it's a mechanism that produces what is semantically a compile-time constant, and can therefore be used in any context in which one is required by the language. C++ has this with constexpr, but it's not as rich in terms of things that it can do. In D, IIRC, pretty much anything goes.
- yvdriess 8y agoIt is ad-hoc in C++, templates weren't designed for general compile time meta-programming. It took several recent changes to the standard to make it a little more palatable with static expressions and general template improvements.