-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
60 lines (47 loc) · 2 KB
/
example.cpp
File metadata and controls
60 lines (47 loc) · 2 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
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <type_traits>
#include <ct_str_t.hpp>
constexpr const char foo[] = "foo"; // const char[4]
constexpr const char* foo2 = "foo"; // const char*
constexpr const char bar[] = "bar"; // const char[4]
constexpr const char* bar2 = "bar"; // const char*
using foo_t = ct_str_t(foo);
using foo2_t = ct_str_t(foo2);
using bar_t = ct_str_t(bar);
using bar2_t = ct_str_t(bar2);
constexpr const wchar_t wfoo[] = L"foo"; // const wchar_t[4]
constexpr const wchar_t* wfoo2 = L"foo"; // const wchar_t*
constexpr const wchar_t wbar[] = L"bar"; // const wchar_t[4]
constexpr const wchar_t* wbar2 = L"bar"; // const wchar_t*
using wfoo_t = ct_str_t(wfoo);
using wfoo2_t = ct_str_t(wfoo);
using wbar_t = ct_str_t(wbar);
using wbar2_t = ct_str_t(wbar);
#define __cat3(_1, _2, _3) \
_1##_2##_3
#define cat3(...) \
__cat3(__VA_ARGS__)
struct cat3(virtual, _, base_t) {};
int main() {
std::cout << typeid(cat3(virtual, _, base_t)).name() << '\n';
// types from the same strings with the same width are the same
static_assert(std::is_same_v<foo_t, foo2_t>);
static_assert(std::is_same_v<bar_t, bar2_t>);
static_assert(std::is_same_v<wfoo_t, wfoo2_t>);
static_assert(std::is_same_v<wbar_t, wbar2_t>);
// types from different strings with the same width are different
static_assert(not std::is_same_v<foo_t, bar2_t>);
static_assert(not std::is_same_v<foo2_t, bar_t>);
static_assert(not std::is_same_v<wfoo_t, wbar2_t>);
static_assert(not std::is_same_v<wfoo2_t, wbar_t>);
// types from the same strings with different width are the same
static_assert(not std::is_same_v<foo_t, wfoo_t>);
static_assert(not std::is_same_v<foo2_t, wfoo2_t>);
static_assert(not std::is_same_v<bar_t, wbar_t>);
static_assert(not std::is_same_v<bar2_t, wbar2_t>);
// types from different strings with different width are the same
static_assert(not std::is_same_v<foo_t, wbar_t>);
static_assert(not std::is_same_v<foo2_t, wbar2_t>);
static_assert(not std::is_same_v<bar_t, wfoo_t>);
static_assert(not std::is_same_v<bar2_t, wfoo2_t>);
}