OKlibrary  0.2.1.6
std_Basics.hpp
Go to the documentation of this file.
00001 // Oliver Kullmann, 24.5.2005 (Swansea)
00002 /* Copyright 2005 - 2007 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00024 #ifndef STDBASICS_pokcc34Ty
00025 #define STDBASICS_pokcc34Ty
00026 
00027 #include <boost/concept_check.hpp>
00028 
00029 #include <OKlib/Concepts/ConceptsBase.hpp>
00030 
00031 namespace OKlib {
00032   namespace Concepts {
00033 
00047     template <typename T>
00048     struct EqualityComparable {
00049       void constraints() {
00050         bool bo;
00051         bo = static_cast<bool>(x == y);
00052         bo = static_cast<bool>(a == b);
00053         bo = static_cast<bool>(a == y);
00054         bo = static_cast<bool>(x == b);
00055       }
00056       T x, y;
00057       const T a, b;
00058     };
00059     struct EqualityComparable_tag : virtual ConceptsBase_tag {};
00060 
00061     class EqualityComparable_Archetype {
00062       EqualityComparable_Archetype();
00063       EqualityComparable_Archetype(const EqualityComparable_Archetype&);
00064       EqualityComparable_Archetype& operator=(const EqualityComparable_Archetype&);
00065       ~EqualityComparable_Archetype();
00066     protected :
00067       struct convertible_to_bool {
00068         operator bool() { return false; }
00069       };
00070     public :
00071       convertible_to_bool operator ==(const EqualityComparable_Archetype&) const { return convertible_to_bool(); }
00072     };
00073 
00074     // --------------------------------------------------------------------------------------------------------------------------------
00075 
00090     template <typename T>
00091     struct LessThanComparable {
00092       void constraints() {
00093         bool bo;
00094         bo = static_cast<bool>(x < y);
00095         bo = static_cast<bool>(a < b);
00096         bo = static_cast<bool>(a < y);
00097         bo = static_cast<bool>(x < b);
00098       }
00099       T x, y;
00100       const T a, b;
00101     };
00102     struct LessThanComparable_tag : virtual ConceptsBase_tag {};
00103 
00104     class LessThanComparable_Archetype {
00105       LessThanComparable_Archetype();
00106       LessThanComparable_Archetype(const LessThanComparable_Archetype&);
00107       LessThanComparable_Archetype& operator=(const LessThanComparable_Archetype&);
00108       ~LessThanComparable_Archetype();
00109     protected :
00110       struct convertible_to_bool {
00111         operator bool() { return false; }
00112       };
00113     public :
00114       convertible_to_bool operator <(const LessThanComparable_Archetype&) const { return convertible_to_bool(); }
00115     };
00116 
00117     // --------------------------------------------------------------------------------------------------------------------------------
00118 
00124     template <class T>
00125     struct Destructible {
00126       void constraints() {
00127         t.~T();
00128       }
00129       T t;
00130     };
00131     struct Destructible_tag : virtual ConceptsBase_tag {};
00132 
00133     class Destructible_Archetype {
00134       Destructible_Archetype();
00135       Destructible_Archetype(const Destructible_Archetype&);
00136       Destructible_Archetype& operator=(const Destructible_Archetype&);
00137     public :
00138       ~Destructible_Archetype() {}
00139     };
00140     
00141     // --------------------------------------------------------------------------------------------------------------------------------
00142 
00153     template <class T>
00154     struct CopyConstructible {
00155       void constraints() {
00156         boost::function_requires<Destructible<T> >();
00157         T x(t);
00158         T y(a);
00159         T* tp;
00160         tp = static_cast<T*>(&t);
00161         tp = &x; tp = &y;
00162         const T* ctp;
00163         ctp = static_cast<const T*>(&a);
00164       } 
00165       T t;
00166       const T a;
00167     };
00168     struct CopyConstructible_tag : virtual Destructible_tag {};
00169 
00170     class CopyConstructible_Archetype {
00171       CopyConstructible_Archetype();
00172       CopyConstructible_Archetype& operator=(const CopyConstructible_Archetype&);
00173     };
00174 
00175     // --------------------------------------------------------------------------------------------------------------------------------
00176 
00182     template <typename T>
00183     struct DefaultConstructible {
00184       void constraints() {
00185         new T;
00186       }
00187     };
00188     struct DefaultConstructible_tag : virtual ConceptsBase_tag {};
00189 
00190     class DefaultConstructible_Archetype {
00191       DefaultConstructible_Archetype(const DefaultConstructible_Archetype&);
00192       DefaultConstructible_Archetype& operator=(const DefaultConstructible_Archetype&);
00193       ~DefaultConstructible_Archetype();
00194     public :
00195       DefaultConstructible_Archetype() {}
00196     };
00197     
00198     // --------------------------------------------------------------------------------------------------------------------------------
00199 
00212     template <typename T>
00213     struct Assignable {
00214       void constraints() {
00215         static_cast<T&>(a = a);
00216         static_cast<T&>(a = b);
00217       }
00218       T a;
00219       const T b; 
00220     };
00221     struct Assignable_tag : virtual ConceptsBase_tag {};
00222 
00223     class Assignable_Archetype {
00224       Assignable_Archetype();
00225       Assignable_Archetype(const Assignable_Archetype&);
00226       ~Assignable_Archetype();
00227     };
00228 
00229   }
00230 
00231 }
00232 
00233 #endif