The limits
namespace offers templated function objects, min
and max
, aimed at fetching the minimum and maximum values of an enumeration, respectively, with compile-time evaluation.
simple_enum::limits::min<enumeration>()
#include <simple_enum/simple_enum.hpp>
enum class ExampleEnum { FirstValue = 1, SecondValue, LastValue };
constexpr ExampleEnum minValue = simple_enum::limits::min<ExampleEnum>();
simple_enum::limits::max<enumeration>()
#include <simple_enum/simple_enum.hpp>
enum class ExampleEnum { FirstValue = 1, SecondValue, LastValue };
constexpr ExampleEnum maxValue = simple_enum::limits::max<ExampleEnum>();
The min
and max
function objects are designed for enumeration types that are considered “bounded”, having well-defined minimum and maximum values that can be determined at compile time. They enhance the usability and safety of enum types in C++, providing clear, compile-time determinable boundaries for such types.