OKlibrary  0.2.1.6
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 
00031 #ifndef BASICS_haharw786
00032 #define BASICS_haharw786
00033 
00034 #include <boost/concept_check.hpp>
00035 
00036 #include <OKlib/Concepts/ConceptsBase.hpp>
00037 #include <OKlib/Concepts/std_Basics.hpp>
00038 
00039 namespace OKlib {
00040   namespace Concepts {
00041 
00050     template <typename T>
00051     struct FullyEqualityComparable {
00052       void constraints() {
00053         boost::function_requires<EqualityComparable<T> >();
00054         bool bo;
00055         bo = static_cast<bool>(x != y);
00056         bo = static_cast<bool>(a != b);
00057         bo = static_cast<bool>(a != y);
00058         bo = static_cast<bool>(x != b);
00059       }
00060       T x, y;
00061       const T a, b;
00062     };
00063     struct FullyEqualityComparable_tag : virtual EqualityComparable_tag {};
00064     // Semantics:
00065     // a != b iff not (a == b).
00066 
00067     class FullyEqualityComparable_Archetype : public EqualityComparable_Archetype {
00068       FullyEqualityComparable_Archetype();
00069       FullyEqualityComparable_Archetype(const FullyEqualityComparable_Archetype&);
00070       FullyEqualityComparable_Archetype& operator=(const FullyEqualityComparable_Archetype&);
00071       ~FullyEqualityComparable_Archetype();
00072     public :
00073       convertible_to_bool operator !=(const FullyEqualityComparable_Archetype&) const { return convertible_to_bool(); }
00074     };
00075 
00076     // ----------------------------------------------------------------------------------------------------------------------
00077 
00083     template <typename T>
00084     struct FullyLessThanComparable {
00085       void constraints() {
00086         boost::function_requires<LessThanComparable<T> >();
00087 
00088         bool bo;
00089         bo = static_cast<bool>(x > y);
00090         bo = static_cast<bool>(a > b);
00091         bo = static_cast<bool>(a > y);
00092         bo = static_cast<bool>(x > b);
00093         bo = static_cast<bool>(x <= y);
00094         bo = static_cast<bool>(a <= b);
00095         bo = static_cast<bool>(a <= y);
00096         bo = static_cast<bool>(x <= b);
00097         bo = static_cast<bool>(x >= y);
00098         bo = static_cast<bool>(a >= b);
00099         bo = static_cast<bool>(a >= y);
00100         bo = static_cast<bool>(x >= b);
00101       }
00102       T x, y;
00103       const T a, b;
00104     };
00105     struct FullyLessThanComparable_tag : virtual LessThanComparable_tag {};
00106     // Semantics: 
00107     // a > b iff b < a
00108     // a <= b iff not (a > b)
00109     // a >= b iff b <= a.
00110 
00111     class FullyLessThanComparable_Archetype : public LessThanComparable_Archetype {
00112       FullyLessThanComparable_Archetype();
00113       FullyLessThanComparable_Archetype(const FullyLessThanComparable_Archetype&);
00114       FullyLessThanComparable_Archetype& operator=(const FullyLessThanComparable_Archetype&);
00115       ~FullyLessThanComparable_Archetype();
00116     public :
00117       convertible_to_bool operator >(const FullyLessThanComparable_Archetype&) const { return convertible_to_bool(); }
00118       convertible_to_bool operator <=(const FullyLessThanComparable_Archetype&) const { return convertible_to_bool(); }
00119       convertible_to_bool operator >=(const FullyLessThanComparable_Archetype&) const { return convertible_to_bool(); }
00120     }; 
00121 
00122     // ----------------------------------------------------------------------------------------------------------------------
00123 
00129     template <typename T>
00130     struct LinearOrder {
00131       void constraints() {
00132         boost::function_requires<FullyLessThanComparable<T> >();
00133         boost::function_requires<FullyEqualityComparable<T> >();
00134       }
00135     };
00136     struct LinearOrder_tag : virtual FullyLessThanComparable_tag, virtual FullyEqualityComparable_tag {};
00137     // Semantics:
00138     // a == b iff (not (a < b) and not (b > a)).
00139 
00140     class LinearOrder_Archetype : public FullyLessThanComparable_Archetype, public FullyEqualityComparable_Archetype {
00141       LinearOrder_Archetype();
00142       LinearOrder_Archetype(const LinearOrder_Archetype&);
00143       LinearOrder_Archetype& operator=(const LinearOrder_Archetype&);
00144       ~LinearOrder_Archetype();
00145     };
00146 
00147     // ----------------------------------------------------------------------------------------------------------------------
00148 
00154     template <typename T>
00155     struct FullyConstructible {
00156       void constraints() {
00157         boost::function_requires<Destructible<T> >();
00158         boost::function_requires<CopyConstructible<T> >();
00159         boost::function_requires<DefaultConstructible<T> >();
00160         boost::function_requires<Assignable<T> >();
00161       }
00162     };
00163     struct FullyConstructible_tag : virtual Destructible_tag, virtual CopyConstructible_tag, virtual DefaultConstructible_tag, virtual Assignable_tag {};
00164 
00165     class FullyConstructible_Archetype {};
00166 
00167     // ----------------------------------------------------------------------------------------------------------------------
00168 
00174     template <typename T>
00175     struct ConstructibleCEq {
00176       void constraints() {
00177         boost::function_requires<FullyEqualityComparable<T> >();
00178         boost::function_requires<Destructible<T> >();
00179         boost::function_requires<CopyConstructible<T> >();
00180       }
00181     };
00182     struct ConstructibleCEq_tag : virtual FullyEqualityComparable_tag, virtual Destructible_tag, virtual CopyConstructible_tag {};
00183 
00184     class ConstructibleCEq_Archetype {
00185       ConstructibleCEq_Archetype();
00186       ConstructibleCEq_Archetype& operator =(const ConstructibleCEq_Archetype&);
00187     protected :
00188       struct convertible_to_bool {
00189         operator bool() { return false; }
00190       };
00191     public :
00192       convertible_to_bool operator ==(const ConstructibleCEq_Archetype&) const { return convertible_to_bool(); }
00193       convertible_to_bool operator !=(const ConstructibleCEq_Archetype&) const { return convertible_to_bool(); }
00194     };
00195 
00201     template <typename T>
00202     struct ConstructibleCAEq {
00203       void constraints() {
00204         boost::function_requires<ConstructibleCEq<T> >();
00205         boost::function_requires<Assignable<T> >();
00206       }
00207     };
00208     struct ConstructibleCAEq_tag : virtual ConstructibleCEq_tag, virtual Assignable_tag {};
00209 
00210     class ConstructibleCAEq_Archetype {
00211       ConstructibleCAEq_Archetype();
00212     protected :
00213       struct convertible_to_bool {
00214         operator bool() { return false; }
00215       };
00216     public :
00217       convertible_to_bool operator ==(const ConstructibleCAEq_Archetype&) const { return convertible_to_bool(); }
00218       convertible_to_bool operator !=(const ConstructibleCAEq_Archetype&) const { return convertible_to_bool(); }
00219     };
00220 
00226     template <typename T>
00227     struct ConstructibleDEq {
00228       void constraints() {
00229         boost::function_requires<FullyEqualityComparable<T> >();
00230         boost::function_requires<DefaultConstructible<T> >();
00231       }
00232     };
00233     struct ConstructibleDEq_tag : virtual FullyEqualityComparable_tag, virtual DefaultConstructible_tag {};
00234 
00235     class ConstructibleDEq_Archetype {
00236       ConstructibleDEq_Archetype(const ConstructibleDEq_Archetype&);
00237       ConstructibleDEq_Archetype& operator =(const ConstructibleDEq_Archetype&);
00238     protected :
00239       struct convertible_to_bool {
00240         operator bool() { return false; }
00241       };
00242     public :
00243       ConstructibleDEq_Archetype() {}
00244       convertible_to_bool operator ==(const ConstructibleDEq_Archetype&) const { return convertible_to_bool(); }
00245       convertible_to_bool operator !=(const ConstructibleDEq_Archetype&) const { return convertible_to_bool(); }
00246     };
00247 
00248 
00254     template <typename T>
00255     struct FullyConstructibleEq {
00256       void constraints() {
00257         boost::function_requires<FullyConstructible<T> >();
00258         boost::function_requires<ConstructibleCAEq<T> >();
00259         boost::function_requires<ConstructibleDEq<T> >();
00260       }
00261     };
00262     struct FullyConstructibleEq_tag : virtual FullyConstructible_tag, virtual ConstructibleCAEq_tag, virtual ConstructibleDEq_tag {};
00263 
00264     class FullyConstructibleEq_Archetype {
00265     protected :
00266       struct convertible_to_bool {
00267         operator bool() { return false; }
00268       };
00269     public :
00270       convertible_to_bool operator ==(const FullyConstructibleEq_Archetype&) const { return convertible_to_bool(); }
00271       convertible_to_bool operator !=(const FullyConstructibleEq_Archetype&) const { return convertible_to_bool(); }
00272     };
00273 
00274     // ----------------------------------------------------------------------------------------------------------------------
00275 
00282     // ----------------------------------------------------------------------------------------------------------------------
00283 
00290     template <typename T>
00291     struct EqualitySubstitutable {
00292       void constraints() {
00293         boost::function_requires<EqualityComparable<T> >();
00294       }
00295     };
00296     struct EqualitySubstitutable_tag : virtual EqualityComparable_tag {};
00297     // Semantics:
00298     // if a == b, then b can be substituted for a everywhere (it might be, that the domain of == is restricted).
00299 
00300     class EqualitySubstitutable_Archetype : public EqualityComparable_Archetype {
00301       EqualitySubstitutable_Archetype();
00302       EqualitySubstitutable_Archetype(const EqualitySubstitutable_Archetype&);
00303       EqualitySubstitutable_Archetype& operator=(const EqualitySubstitutable_Archetype&);
00304       ~EqualitySubstitutable_Archetype();
00305     };
00306 
00316     template <typename T>
00317     struct ConstCorrect {
00318       void constraints() {}
00319     };
00320     struct ConstCorrect_tag : virtual ConceptsBase_tag {};
00321     // Semantics:
00322     // Operations allowed for const T objects applied to const T objects maintain substitutability.
00323 
00324     class ConstCorrect_Archetype {
00325       ConstCorrect_Archetype();
00326       ConstCorrect_Archetype(const ConstCorrect_Archetype&);
00327       ConstCorrect_Archetype& operator=(const ConstCorrect_Archetype&);
00328       ~ConstCorrect_Archetype();
00329     };
00330 
00331   }
00332 
00333 }
00334 
00335 #endif