-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (55 loc) · 1.41 KB
/
main.cpp
File metadata and controls
70 lines (55 loc) · 1.41 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
61
62
63
64
65
66
67
68
69
70
#include "array"
#include <type_traits>
constexpr int array_size = 8;
using element_t = int;
struct ref{};
ref foo( element_t (&ar)[array_size] ){
return {};
}
struct const_ref{};
const_ref foo( const element_t (&ar)[array_size] ){
return {};
}
struct pointer {};
pointer foo( element_t (*ar)[array_size] ){
return {};
}
struct const_pointer{};
const_pointer foo( const element_t (*ar)[array_size] ){
return {};
}
struct rvalue_ref{};
rvalue_ref foo( element_t (&&ar)[array_size] ){
return {};
}
template<typename Expected, typename Actual>
void assert_type_is(Actual &&) {
static_assert(std::is_same_v<Expected, Actual>, "Types are not the same");
}
int main()
{
using array_t = std::array<element_t, array_size>;
{
array_t arr = {0};
assert_type_is<ref>(foo(arr.c_array()));
assert_type_is<pointer>(foo(&arr.c_array()));
}
{
const array_t arr = {0};
assert_type_is<const_ref>(foo(arr.c_array()));
assert_type_is<const_pointer>(foo(&arr.c_array()));
}
{
auto get_arr = []()->array_t{
return {0};
};
assert_type_is<rvalue_ref>(foo(get_arr().c_array()));
}
{
auto get_arr = []()->const array_t{
return {0};
};
assert_type_is<const_ref>(foo(get_arr().c_array()));
}
return 0;
}