Robert Ramey
On 6/19/15 1:40 AM, Mathias Gaunard wrote:
What template meta-programming were you able to replace by constexpr?
As far as I'm concerned, I've yet to see a use case where constexpr is anything but an optimization hint.
Hmmm - what about all the mpl arithmetic functions built around mpl integral constants? All that gets replace by easy to understand compile time expressions which can be used in other template expressions? This simplifies things immensely.
As far as my current experience goes, this is one of the only use cases where constexpr can help (but it does help a lot in that case). You can replace complex arithmetic with equivalent constexpr code and it's going to be much simpler to read and also more efficient at compile-time. It's also possible to use constexpr to do some index calculations as an implementation detail of an heterogeneous algorithm. For example, to compute the cartesian product of tuples, I actually generate the proper sequence of indices using constexpr computations, and then index the sequences with these indices, getting back a tuple of tuples. But that's hardly useful outside of deep TMP algorithms. Louis