class template
<type_traits>
std::underlying_typetemplate <class T> struct underlying_type;
Underlying type of enum
Obtains the underlying type of enum type T.The underlying type is aliased as member type underlying_type::type.
The underlying type of an enum declared with enum class is int unless a different type is specified on declaration.
Notice that this class merely obtains a type using another type as model, but it does not transform values or objects between those types.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// underlying_type example
#include <iostream>
#include <type_traits>
enum class A {a,b,c};
enum B : short {x,y,z};
int main() {
typedef std::underlying_type<A>::type A_under; // int
typedef std::underlying_type<B>::type B_under; // short
std::cout << std::boolalpha;
std::cout << "typedefs of int:" << std::endl;
std::cout << "A_under: " << std::is_same<int,A_under>::value << std::endl;
std::cout << "B_under: " << std::is_same<int,B_under>::value << std::endl;
return 0;
}
typedefs of int: A_under: true B_under: false
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4