-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathToUnderlying.cpp
More file actions
48 lines (39 loc) · 1.27 KB
/
ToUnderlying.cpp
File metadata and controls
48 lines (39 loc) · 1.27 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// =====================================================================================
// ToUnderlying.cpp
// =====================================================================================
module modern_cpp:to_underlying;
namespace ToUnderlying {
enum class Color : char {
Red = 'R',
Green = 'G',
Blue = 'B'
};
enum class Weekdays : int {
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6,
Sunday = 7,
};
static void test_01()
{
Color color{ Color::Blue };
auto colorCode{ std::to_underlying(color) };
static_assert(std::is_same<decltype(colorCode), char>::value);
std::println("Color Code: {}", colorCode);
Weekdays day{ Weekdays::Friday };
int dayCode{ std::to_underlying(day) };
static_assert(std::is_same<decltype(dayCode), int>::value);
std::println("Weekday Code: {}", dayCode);
}
}
void main_to_underlying()
{
using namespace ToUnderlying;
test_01();
}
// =====================================================================================
// End-of-File
// =====================================================================================