-
Notifications
You must be signed in to change notification settings - Fork 2
/
week5-app1.cpp
54 lines (40 loc) · 1.6 KB
/
week5-app1.cpp
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
// l-value, r-value bindings:
// function parameter call site argument
// l-value to l_value - works (clones the value)
// l-value to r_value - works (clones the value)
// l-value ref to l_value - works
// l-value ref to r_value - does not work
// const l-value ref to l_value - works
// const l-value ref to r_value - works
// const r-value ref - does not make sense most of the time
// TypeDisplay trick
// reference collapsing
// std::remove_reference<T>::type
// Write a Value<T> class that uses heap memory for storage! with all ctors and dtors
// initializer_list<T>
// move-ctor, move-assignment
// a Stack<T> implementation
#include <iostream>
using namespace std; // namespace import into our namespace. do not ever use this in a header file!
// template<typename T> struct RemoveRef { using type = T; };
// template<typename K> struct RemoveRef<K&> { using type = K; };
// template<typename K> struct RemoveRef<K&&> { using type = K; };
// forward declaration
template<typename T>
struct TypeDisplay;
using int_ref = int&;
using int_ref_ref = int&&;
void func(int_ref i) {
}
int main(int argc, char* argv[])
{
auto i = 5;
func(i);
// auto t1 = TypeDisplay<int_ref&>{}; // &
// auto t2 = TypeDisplay<int_ref&&>{}; // &
// auto t3 = TypeDisplay<int_ref_ref&>{}; // &
// auto t4 = TypeDisplay<int_ref_ref>{}; // &&
// using K = std::remove_reference<int&&>::type;
// auto k = TypeDisplay<K>{};
return 0;
}