-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA14-5-1.cpp
More file actions
97 lines (60 loc) · 1.26 KB
/
A14-5-1.cpp
File metadata and controls
97 lines (60 loc) · 1.26 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Rule: A14-5-1
// Source line: 20749
// Original file: A14-5-1.cpp
// $Id: A14-5-1.cpp 309903 2018-03-02 12:54:18Z christof.meerwald $
#include <cstdint>
#include <type_traits>
class A
{
public:
// Compliant: template constructor does not participate in overload
//
resolution for copy/move operations
template<typename T,
std::enable_if_t<! std::is_same<std::remove_cv_t<T>, A>::value> * =
nullptr>
A(const T &value)
: m_value { value }
{ }
private:
std::int32_t m_value;
};
void Foo(A const &a)
{
A myA { a }; // will use the implicit copy ctor, not the template converting
ctor
A a2 { 2 };
// will use the template converting ctor
}
class B
{
public:
B(const B &) = default;
B(B &&) = default;
// Compliant: forwarding constructor does not participate in overload
//
resolution for copy/move operations
template<typename T,
std::enable_if_t<! std::is_same<std::remove_cv_t<std::
remove_reference_t<T>>, B>::value> * = nullptr>
B(T &&value);
};
void Bar(B b)
{
B myB { b };
}
// will use the copy ctor, not the forwarding ctor
class C
{
public:
C(const C &) = default;
C(C &&) = default;
// Non-Compliant: unconstrained template constructor
template<typename T>
C(T &);
};
void Bar(C c)
{
C myC { c };
}
// will use template ctor instead of copy ctor