containers.hpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Ifdefs
00010 *****************************************************************************/
00011 
00012 #ifndef ECL_CONCEPTS_CONCEPTS_CONTAINERS_HPP_
00013 #define ECL_CONCEPTS_CONCEPTS_CONTAINERS_HPP_
00014 
00015 /*****************************************************************************
00016 ** Includes
00017 *****************************************************************************/
00018 
00019 #include <ecl/config/ecl.hpp>
00020 #include <ecl/type_traits/fundamental_types.hpp>
00021 #include "macros.hpp"
00022 
00023 /*****************************************************************************
00024 ** Namespaces
00025 *****************************************************************************/
00026 
00027 namespace ecl {
00028 
00029 /*****************************************************************************
00030 ** Concept [Container]
00031 *****************************************************************************/
00032 
00036 template <typename Implementation>
00037 class ContainerConcept {
00038 public:
00039 
00050         ecl_compile_time_concept_test(ContainerConcept)
00051         {
00052                 iter = container.begin();
00053                 iter = container.end();
00054                 unsigned int n;
00055                 n = container.size();
00056                 (void) n; // remove set but not used warnings.
00057         }
00058 
00059 private:
00060         // Putting instantiations here actually saves instantiation (which can cause a
00061         // problem if there is no default constructor).
00062         Implementation container;
00063         typename Implementation::iterator iter;
00064 };
00068 template <typename Implementation>
00069 class DynamicContainerConcept {
00070 public:
00071 
00083         ecl_compile_time_concept_test(DynamicContainerConcept)
00084         {
00085                 iter = container.begin();
00086                 iter = container.end();
00087                 unsigned int n;
00088                 n = container.size();
00089                 container.resize(1);
00090                 (void) n; // remove set but not used warnings.
00091         }
00092 
00093 private:
00094         // Putting instantiations here actually saves instantiation (which can cause a
00095         // problem if there is no default constructor).
00096         Implementation container;
00097         typename Implementation::iterator iter;
00098 };
00099 
00103 namespace concepts {
00104 
00114 template <typename T, bool Result=false>
00115 class SignedByteTest {
00116 private:
00117         SignedByteTest() {}
00118 };
00119 
00129 template <typename T>
00130 class SignedByteTest<T,true> {
00131 public:
00132         SignedByteTest() {}
00133 };
00134 
00144 template <typename T, bool Result=false>
00145 class UnsignedByteTest {
00146 private:
00147         UnsignedByteTest() {}
00148 };
00149 
00159 template <typename T>
00160 class UnsignedByteTest<T,true> {
00161 public:
00162         UnsignedByteTest() {}
00163 };
00164 
00171 template <typename T>
00172 class SignedByteTestCheck : public SignedByteTest<T, ecl::is_signed_byte<T>::value > {};
00173 
00180 template <typename T>
00181 class UnsignedByteTestCheck : public UnsignedByteTest<T, ecl::is_unsigned_byte<T>::value > {};
00182 
00191 template <typename T>
00192 class ByteTest {
00193 private:
00194         ByteTest() {}
00195 };
00196 
00205 template <>
00206 class ByteTest<unsigned char> {
00207 public:
00208         ByteTest() {}
00209 };
00213 template <>
00214 class ByteTest<char> {
00215 public:
00216         ByteTest() {}
00217 };
00218 
00222 template <>
00223 class ByteTest<signed char> {
00224 public:
00225         ByteTest() {}
00226 };
00227 
00228 } // namespace concepts
00236 template <typename Implementation>
00237 class UnsignedByteContainerConcept {
00238 public:
00239 
00249         ecl_compile_time_concept_test(UnsignedByteContainerConcept)
00250         {
00251                 typedef typename Implementation::value_type element_type;
00252                 iter = container.begin();
00253                 iter = container.end();
00254                 unsigned int n;
00255                 n = container.size();
00256                 // If not a char, this results in a private call -> compile time error!
00257                 concepts::UnsignedByteTestCheck<element_type> char_test;
00258                 (void) n; // remove set but unused warnings.
00259         }
00260 
00261 private:
00262         // Putting instantiations here actually saves instantiation (which can cause a
00263         // problem if there is no default constructor).
00264         Implementation container;
00265         typename Implementation::iterator iter;
00266 };
00267 
00271 template <typename Implementation>
00272 class SignedByteContainerConcept {
00273 public:
00274 
00284         ecl_compile_time_concept_test(SignedByteContainerConcept)
00285         {
00286                 typedef typename Implementation::value_type element_type;
00287                 iter = container.begin();
00288                 iter = container.end();
00289                 unsigned int n;
00290                 n = container.size();
00291                 // If not a char, this results in a private call -> compile time error!
00292                 concepts::SignedByteTestCheck<element_type> char_test;
00293         }
00294 
00295 private:
00296         // Putting instantiations here actually saves instantiation (which can cause a
00297         // problem if there is no default constructor).
00298         Implementation container;
00299         typename Implementation::iterator iter;
00300 };
00301 
00307 template <typename Implementation>
00308 class ByteContainerConcept {
00309 public:
00310 
00320         ecl_compile_time_concept_test(ByteContainerConcept)
00321         {
00322                 typedef typename Implementation::value_type element_type;
00323                 iter = container.begin();
00324                 iter = container.end();
00325                 unsigned int n;
00326                 n = container.size();
00327                 // If not a char, this results in a private call -> compile time error!
00328                 concepts::ByteTest<element_type> char_test;
00329                 (void) n; // remove set but unused warnings.
00330         }
00331 
00332 private:
00333         // Putting instantiations here actually saves instantiation (which can cause a
00334         // problem if there is no default constructor).
00335         Implementation container;
00336         typename Implementation::iterator iter;
00337 };
00338 
00339 }; // namespace ecl
00340 
00341 #endif /* ECL_CONCEPTS_CONCEPTS_CONTAINERS_HPP_ */


ecl_concepts
Author(s): Daniel Stonier
autogenerated on Mon Jul 3 2017 02:21:27