Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are numeric_limits min/max constexpr?

Does the C++11 standard specify that the numeric_limits<T>::min and max have to be constant-expression that can be used in templates or static_assert?

More generally, how to find the list of the functions that are constant-expression according to the standard?

like image 851
Vincent Avatar asked Sep 02 '12 22:09

Vincent


1 Answers

Indeed the standard (or my latest working draft) lists all members of std::numeric_limits in chapter 18.3.2.3 [numeric.limits] as constexpr (it won't do any good to actually quote those definitions here), for the general templated version as well as all the builtin specializations (18.3.2.7 [numeric.special]). So yes, they are guaranteed to be constant expressions (for conforming implementations that also actually support constexpr, of course).

As to your second, more general, question I cannot help you that much except just refer you to the C++ standard itself, whose latest draft, which doesn't really differ from the actual standard, is available for free. Or you might look at the more convenient but less binding cppreference.com.

like image 65
Christian Rau Avatar answered Sep 24 '22 02:09

Christian Rau