concepts/containers.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_CONCEPTS_CONCEPTS_CONTAINERS_HPP_
13 #define ECL_CONCEPTS_CONCEPTS_CONTAINERS_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <ecl/config/ecl.hpp>
20 #include <ecl/type_traits/fundamental_types.hpp>
21 #include "macros.hpp"
22 
23 /*****************************************************************************
24 ** Namespaces
25 *****************************************************************************/
26 
27 namespace ecl {
28 
29 /*****************************************************************************
30 ** Concept [Container]
31 *****************************************************************************/
32 
36 template <typename Implementation>
37 class ContainerConcept {
38 public:
39 
50  ecl_compile_time_concept_test(ContainerConcept)
51  {
52  iter = container.begin();
53  iter = container.end();
54  unsigned int n;
55  n = container.size();
56  (void) n; // remove set but not used warnings.
57  }
58 
59 private:
60  // Putting instantiations here actually saves instantiation (which can cause a
61  // problem if there is no default constructor).
62  Implementation container;
63  typename Implementation::iterator iter;
64 };
68 template <typename Implementation>
69 class DynamicContainerConcept {
70 public:
71 
83  ecl_compile_time_concept_test(DynamicContainerConcept)
84  {
85  iter = container.begin();
86  iter = container.end();
87  unsigned int n;
88  n = container.size();
89  container.resize(1);
90  (void) n; // remove set but not used warnings.
91  }
92 
93 private:
94  // Putting instantiations here actually saves instantiation (which can cause a
95  // problem if there is no default constructor).
96  Implementation container;
97  typename Implementation::iterator iter;
98 };
99 
103 namespace concepts {
104 
114 template <typename T, bool Result=false>
115 class SignedByteTest {
116 private:
117  SignedByteTest() {}
118 };
119 
129 template <typename T>
130 class SignedByteTest<T,true> {
131 public:
132  SignedByteTest() {}
133 };
134 
144 template <typename T, bool Result=false>
145 class UnsignedByteTest {
146 private:
147  UnsignedByteTest() {}
148 };
149 
159 template <typename T>
160 class UnsignedByteTest<T,true> {
161 public:
162  UnsignedByteTest() {}
163 };
164 
171 template <typename T>
172 class SignedByteTestCheck : public SignedByteTest<T, ecl::is_signed_byte<T>::value > {};
173 
180 template <typename T>
181 class UnsignedByteTestCheck : public UnsignedByteTest<T, ecl::is_unsigned_byte<T>::value > {};
182 
191 template <typename T>
192 class ByteTest {
193 private:
194  ByteTest() {}
195 };
196 
205 template <>
206 class ByteTest<unsigned char> {
207 public:
208  ByteTest() {}
209 };
213 template <>
214 class ByteTest<char> {
215 public:
216  ByteTest() {}
217 };
218 
222 template <>
223 class ByteTest<signed char> {
224 public:
225  ByteTest() {}
226 };
227 
228 } // namespace concepts
236 template <typename Implementation>
237 class UnsignedByteContainerConcept {
238 public:
239 
249  ecl_compile_time_concept_test(UnsignedByteContainerConcept)
250  {
251  typedef typename Implementation::value_type element_type;
252  iter = container.begin();
253  iter = container.end();
254  unsigned int n;
255  n = container.size();
256  // If not a char, this results in a private call -> compile time error!
257  concepts::UnsignedByteTestCheck<element_type> char_test;
258  (void) n; // remove set but unused warnings.
259  }
260 
261 private:
262  // Putting instantiations here actually saves instantiation (which can cause a
263  // problem if there is no default constructor).
264  Implementation container;
265  typename Implementation::iterator iter;
266 };
267 
271 template <typename Implementation>
272 class SignedByteContainerConcept {
273 public:
274 
284  ecl_compile_time_concept_test(SignedByteContainerConcept)
285  {
286  typedef typename Implementation::value_type element_type;
287  iter = container.begin();
288  iter = container.end();
289  unsigned int n;
290  n = container.size();
291  // If not a char, this results in a private call -> compile time error!
292  concepts::SignedByteTestCheck<element_type> char_test;
293  }
294 
295 private:
296  // Putting instantiations here actually saves instantiation (which can cause a
297  // problem if there is no default constructor).
298  Implementation container;
299  typename Implementation::iterator iter;
300 };
301 
307 template <typename Implementation>
308 class ByteContainerConcept {
309 public:
310 
320  ecl_compile_time_concept_test(ByteContainerConcept)
321  {
322  typedef typename Implementation::value_type element_type;
323  iter = container.begin();
324  iter = container.end();
325  unsigned int n;
326  n = container.size();
327  // If not a char, this results in a private call -> compile time error!
328  concepts::ByteTest<element_type> char_test;
329  (void) n; // remove set but unused warnings.
330  }
331 
332 private:
333  // Putting instantiations here actually saves instantiation (which can cause a
334  // problem if there is no default constructor).
335  Implementation container;
336  typename Implementation::iterator iter;
337 };
338 
339 }; // namespace ecl
340 
341 #endif /* ECL_CONCEPTS_CONCEPTS_CONTAINERS_HPP_ */
Pre-processed macro definitions that define the target platform.
ecl_compile_time_concept_test(ContainerConcept)
Implementation::iterator iter


xbot_driver
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:27:37