-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove_forwarding_1.cpp
66 lines (55 loc) · 1.33 KB
/
move_forwarding_1.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
55
56
57
58
59
60
61
62
63
64
65
66
#include <utility>
#include <string>
#include <iostream>
#include <type_traits>
#include <array>
template <typename T>
using EnableIfString = std::enable_if_t<std::is_convertible_v<T, std::string>>;
class Person
{
private:
std::string name;
public:
template <typename STR, typename = EnableIfString<STR>>
explicit Person(STR &&n) : name(std::forward<STR>(n))
{
std::cout << "TMPL-CONSTR for '" << name << "'\n";
}
Person(Person const &p) : name(p.name)
{
std::cout << "COPY-CONSTR Person '" << name << "'\n";
}
Person(Person &&p) : name(std::move(p.name))
{
std::cout << "MOVE-CONSTR Person '" << name << "'\n";
}
};
template <typename T>
void outR(T &arg)
{
if (std::is_array<T>::value)
{
std::cout << "got array of " << std::extent<T>::value << " elems\n";
}
else
{
std::cout << "T is not an array\n";
}
}
int main()
{
// std::string s = "sname";
// Person p1(s);
// Person p2("tmp");
// Person p3(p1);
// Person p4(std::move(p1));
// const Person p2c("ctmp");
// Person p3c(p2c);
// std::cout << p1.name << std::endl;
std::cout << std::boolalpha;
int a[] = {1, 2, 3, 4, 5};
std::cout << std::is_array<int []>::value << std::endl;
std::array<int, 4> b = {5, 6, 7, 8};
outR(a);
outR(b);
}