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                 typedef typename Implementation::value_type element_type;
00053                 typedef typename Implementation::iterator iterator;
00054                 iter = container.begin();
00055                 iter = container.end();
00056                 unsigned int n;
00057                 n = container.size();
00058                 (void) n; // remove set but not used warnings.
00059         }
00060 
00061 private:
00062         // Putting instantiations here actually saves instantiation (which can cause a
00063         // problem if there is no default constructor).
00064         Implementation container;
00065         typename Implementation::iterator iter;
00066 };
00070 template <typename Implementation>
00071 class DynamicContainerConcept {
00072 public:
00073 
00085         ecl_compile_time_concept_test(DynamicContainerConcept)
00086         {
00087                 typedef typename Implementation::value_type element_type;
00088                 typedef typename Implementation::iterator iterator;
00089                 iter = container.begin();
00090                 iter = container.end();
00091                 unsigned int n;
00092                 n = container.size();
00093                 container.resize(1);
00094                 (void) n; // remove set but not used warnings.
00095         }
00096 
00097 private:
00098         // Putting instantiations here actually saves instantiation (which can cause a
00099         // problem if there is no default constructor).
00100         Implementation container;
00101         typename Implementation::iterator iter;
00102 };
00103 
00107 namespace concepts {
00108 
00118 template <typename T, bool Result=false>
00119 class SignedByteTest {
00120 private:
00121         SignedByteTest() {}
00122 };
00123 
00133 template <typename T>
00134 class SignedByteTest<T,true> {
00135 public:
00136         SignedByteTest() {}
00137 };
00138 
00148 template <typename T, bool Result=false>
00149 class UnsignedByteTest {
00150 private:
00151         UnsignedByteTest() {}
00152 };
00153 
00163 template <typename T>
00164 class UnsignedByteTest<T,true> {
00165 public:
00166         UnsignedByteTest() {}
00167 };
00168 
00175 template <typename T>
00176 class SignedByteTestCheck : public SignedByteTest<T, ecl::is_signed_byte<T>::value > {};
00177 
00184 template <typename T>
00185 class UnsignedByteTestCheck : public UnsignedByteTest<T, ecl::is_unsigned_byte<T>::value > {};
00186 
00195 template <typename T>
00196 class ByteTest {
00197 private:
00198         ByteTest() {}
00199 };
00200 
00209 template <>
00210 class ByteTest<unsigned char> {
00211 public:
00212         ByteTest() {}
00213 };
00217 template <>
00218 class ByteTest<char> {
00219 public:
00220         ByteTest() {}
00221 };
00222 
00226 template <>
00227 class ByteTest<signed char> {
00228 public:
00229         ByteTest() {}
00230 };
00231 
00232 } // namespace concepts
00240 template <typename Implementation>
00241 class UnsignedByteContainerConcept {
00242 public:
00243 
00253         ecl_compile_time_concept_test(UnsignedByteContainerConcept)
00254         {
00255                 typedef typename Implementation::value_type element_type;
00256                 typedef typename Implementation::iterator iterator;
00257                 iter = container.begin();
00258                 iter = container.end();
00259                 unsigned int n;
00260                 n = container.size();
00261                 // If not a char, this results in a private call -> compile time error!
00262                 concepts::UnsignedByteTestCheck<element_type> char_test;
00263                 (void) n; // remove set but unused warnings.
00264         }
00265 
00266 private:
00267         // Putting instantiations here actually saves instantiation (which can cause a
00268         // problem if there is no default constructor).
00269         Implementation container;
00270         typename Implementation::iterator iter;
00271 };
00272 
00276 template <typename Implementation>
00277 class SignedByteContainerConcept {
00278 public:
00279 
00289         ecl_compile_time_concept_test(SignedByteContainerConcept)
00290         {
00291                 typedef typename Implementation::value_type element_type;
00292                 typedef typename Implementation::iterator iterator;
00293                 iter = container.begin();
00294                 iter = container.end();
00295                 unsigned int n;
00296                 n = container.size();
00297                 // If not a char, this results in a private call -> compile time error!
00298                 concepts::SignedByteTestCheck<element_type> char_test;
00299         }
00300 
00301 private:
00302         // Putting instantiations here actually saves instantiation (which can cause a
00303         // problem if there is no default constructor).
00304         Implementation container;
00305         typename Implementation::iterator iter;
00306 };
00307 
00313 template <typename Implementation>
00314 class ByteContainerConcept {
00315 public:
00316 
00326         ecl_compile_time_concept_test(ByteContainerConcept)
00327         {
00328                 typedef typename Implementation::value_type element_type;
00329                 typedef typename Implementation::iterator iterator;
00330                 iter = container.begin();
00331                 iter = container.end();
00332                 unsigned int n;
00333                 n = container.size();
00334                 // If not a char, this results in a private call -> compile time error!
00335                 concepts::ByteTest<element_type> char_test;
00336                 (void) n; // remove set but unused warnings.
00337         }
00338 
00339 private:
00340         // Putting instantiations here actually saves instantiation (which can cause a
00341         // problem if there is no default constructor).
00342         Implementation container;
00343         typename Implementation::iterator iter;
00344 };
00345 
00346 }; // namespace ecl
00347 
00348 #endif /* ECL_CONCEPTS_CONCEPTS_CONTAINERS_HPP_ */


ecl_concepts
Author(s): Daniel Stonier
autogenerated on Wed Aug 26 2015 11:27:09