-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunderlying_type_t_test.cpp
More file actions
32 lines (29 loc) · 949 Bytes
/
Copy pathunderlying_type_t_test.cpp
File metadata and controls
32 lines (29 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// Created by william on 2021/7/17.
//
#include "base.h"
// IfT是一个完整的枚举 (enum) 类型,提供一个成员 typedeftype来命名T.
enum e1
{
};
enum class e2
{
};
enum class e3 : unsigned
{
};
enum class e4 : int
{
};
void underlying_type_t_test()
{
constexpr bool e1_t = std::is_same_v<std::underlying_type_t<e1>, unsigned int>;
constexpr bool e2_t = std::is_same_v<std::underlying_type_t<e2>, int>;
constexpr bool e3_t = std::is_same_v<std::underlying_type_t<e3>, unsigned>;
constexpr bool e4_t = std::is_same_v<std::underlying_type_t<e4>, int>;
std::cout
<< "underlying type for 'e1' is " << (e1_t ? "unsigned int" : "non-unsigned int") << '\n'
<< "underlying type for 'e2' is " << (e2_t ? "int" : "non-int") << '\n'
<< "underlying type for 'e3' is " << (e3_t ? "unsigned" : "unsigned-int") << '\n'
<< "underlying type for 'e4' is " << (e4_t ? "int" : "non-int") << '\n';
}