carl  24.04
Computer ARithmetic Library
enum_util.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <limits>
4 #include <type_traits>
5 
6 namespace carl {
7 
8 /**
9  * Returns an enum value that is (most probably) not a valid enum value.
10  * This can be used to check whether methods that take enums properly handle invalid values.
11  */
12 template<typename Enum>
13 constexpr Enum invalid_enum_value() {
14  return static_cast<Enum>(std::numeric_limits<typename std::underlying_type<Enum>::type>::max());
15 }
16 
17 /**
18  * Casts an enum value to a value of the underlying number type.
19  */
20 template<typename Enum>
21 constexpr auto underlying_enum_value(Enum e) {
22  return static_cast<typename std::underlying_type<Enum>::type>(e);
23 }
24 
25 }
carl is the main namespace for the library.
constexpr auto underlying_enum_value(Enum e)
Casts an enum value to a value of the underlying number type.
Definition: enum_util.h:21
constexpr Enum invalid_enum_value()
Returns an enum value that is (most probably) not a valid enum value.
Definition: enum_util.h:13