Nugget
ConceptImpls.h
1 // Copyright (c) Electronic Arts Inc. All rights reserved.
4 
5 #ifndef CONCEPTSIMPLS_H
6 #define CONCEPTSIMPLS_H
7 
8 #include <EASTL/type_traits.h>
9 
10 #if !defined(EA_COMPILER_NO_DEFAULTED_FUNCTIONS) && !defined(EA_COMPILER_NO_DELETED_FUNCTIONS)
11 
12 #define EASTL_TEST_CONCEPT_IMPLS
13 
14 // This header provides a variety of helper classes that have interfaces corresponding to the concepts used to specify
15 // requirements of many STL containers and algorithms. These helper classes are used in tests to verify that containers
16 // and algorithms do not impose stricter requirements than specified by the standard on their arguments.
17 
18 // Destructible - only valid operation on this class is to destroy it.
19 
21 {
22 public:
23  ~Destructible() = default;
24 
25  Destructible() = delete;
26  Destructible(const Destructible&) = delete;
27  Destructible(Destructible&&) = delete;
28  Destructible& operator=(const Destructible&) = delete;
29  Destructible& operator=(Destructible&&) = delete;
30 };
31 
32 // Unfortunately not all compilers handle type_traits reliably correctly currently so we can't straightforwardly
33 // static_assert everything that should be true of this class
34 static_assert(eastl::is_destructible<Destructible>::value, "eastl::is_destructible<Destructible>::value");
35 // static_assert(!eastl::is_default_constructible<Destructible>::value,
36 // "!eastl::is_default_constructible<Destructible>::value");
37 // static_assert(!is_copy_constructible<Destructible>::value, "!eastl::is_copy_constructible<Destructible>::value");
38 static_assert(!eastl::is_copy_assignable<Destructible>::value, "!eastl::is_copy_assignable<Destructible>::value");
39 // static_assert(!eastl::is_move_constructible<Destructible>::value,
40 // "!eastl::is_move_constructible<Destructible>::value");
41 static_assert(!eastl::is_move_assignable<Destructible>::value, "!eastl::is_move_assignable<Destructible>::value");
42 
44 {
45 public:
46  static const int defaultValue = 42;
47 
48  DefaultConstructible() : value(defaultValue) {}
49  ~DefaultConstructible() = default;
50 
53  DefaultConstructible& operator=(const DefaultConstructible&) = delete;
54  DefaultConstructible& operator=(DefaultConstructible&&) = delete;
55 
56  const int value;
57 };
58 
59 
61 {
62  NotDefaultConstructible() = delete;
63 };
64 static_assert(!eastl::is_default_constructible<NotDefaultConstructible>::value, "'NotDefaultConstructible' is default constructible.");
65 
66 
68 {
69 public:
70  static const int defaultValue = 42;
71  static CopyConstructible Create()
72  {
74  return x;
75  }
76 
77  CopyConstructible(const CopyConstructible&) = default;
78  ~CopyConstructible() = default;
79 
80  CopyConstructible& operator=(const CopyConstructible&) = delete;
81  CopyConstructible& operator=(CopyConstructible&&) = delete;
82 
83  const int value;
84 
85 private:
86  CopyConstructible() : value(defaultValue) {}
87 };
88 
89 // Unfortunately not all compilers handle type_traits reliably correctly currently so we can't straightforwardly
90 // static_assert everything that should be true of this class
91 static_assert(eastl::is_destructible<CopyConstructible>::value, "eastl::is_destructible<CopyConstructible>::value");
92 // static_assert(!eastl::is_default_constructible<CopyConstructible>::value,
93 // "!eastl::is_default_constructible<CopyConstructible>::value");
94 // static_assert(is_copy_constructible<CopyConstructible>::value, "is_copy_constructible<CopyConstructible>::value");
96  "eastl::is_copy_constructible<CopyConstructible>::value");
98  "!eastl::is_copy_assignable<CopyConstructible>::value");
99 // static_assert(!eastl::is_move_constructible<CopyConstructible>::value,
100 // "!eastl::is_move_constructible<CopyConstructible>::value");
102  "!eastl::is_move_assignable<CopyConstructible>::value");
103 
105 {
106 public:
107  static const int defaultValue = 42;
108  static MoveConstructible Create()
109  {
110  return MoveConstructible{};
111  }
112 
113  MoveConstructible(MoveConstructible&& x) : value(x.value) {}
114  ~MoveConstructible() = default;
115 
116  MoveConstructible(const MoveConstructible&) = delete;
117  MoveConstructible& operator=(const MoveConstructible&) = delete;
118  MoveConstructible& operator=(MoveConstructible&&) = delete;
119 
120  const int value;
121 
122 private:
123  MoveConstructible() : value(defaultValue) {}
124 };
125 
127 {
128 public:
129  static const int defaultValue = 42;
130  static MoveAssignable Create()
131  {
132  return MoveAssignable{};
133  }
134 
135  MoveAssignable(MoveAssignable&& x) : value(x.value) {}
136  MoveAssignable& operator=(MoveAssignable&& x)
137  {
138  value = x.value;
139  return *this;
140  }
141  ~MoveAssignable() = default;
142 
143  MoveAssignable(const MoveAssignable&) = delete;
144  MoveAssignable& operator=(const MoveAssignable&) = delete;
145 
146  int value;
147 
148 private:
149  MoveAssignable() : value(defaultValue) {}
150 };
151 
153 {
154  static const int defaultValue = 42;
155 
156  MoveAndDefaultConstructible() : value(defaultValue) {}
158  ~MoveAndDefaultConstructible() = default;
159 
161  MoveAndDefaultConstructible& operator=(const MoveAndDefaultConstructible&) = delete;
163 
164  const int value;
165 };
166 
168 {
171  MissingMoveConstructor& operator=(MissingMoveConstructor&&) { return *this; }
172  MissingMoveConstructor& operator=(const MissingMoveConstructor&) { return *this; }
173  bool operator<(const MissingMoveConstructor&) const { return true; }
174 };
175 
177 {
181  MissingMoveAssignable& operator=(const MissingMoveAssignable&) { return *this; }
182  bool operator<(const MissingMoveAssignable&) const { return true; }
183 };
184 
186 {
187  MissingEquality& operator==(const MissingEquality&) = delete;
188 };
189 
190 #endif // !defined(EA_COMPILER_NO_DEFAULTED_FUNCTIONS) && !defined(EA_COMPILER_NO_DELETED_FUNCTIONS)
191 
192 #endif // CONCEPTSIMPLS_H
Definition: ConceptImpls.h:68
Definition: ConceptImpls.h:44
Definition: ConceptImpls.h:21
Definition: ConceptImpls.h:127
Definition: ConceptImpls.h:105
Definition: ConceptImpls.h:186
Definition: ConceptImpls.h:177
Definition: ConceptImpls.h:168
Definition: ConceptImpls.h:153
Definition: ConceptImpls.h:61
Definition: type_pod.h:1557
Definition: type_pod.h:1175
Definition: type_pod.h:1149
Definition: type_pod.h:1740
Definition: type_pod.h:1628