Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65697 - sandbox/opaque/boost/opaque
From: vicente.botet_at_[hidden]
Date: 2010-09-30 16:28:37


Author: viboes
Date: 2010-09-30 16:28:36 EDT (Thu, 30 Sep 2010)
New Revision: 65697
URL: http://svn.boost.org/trac/boost/changeset/65697

Log:
Opaque:
* Parameterize the boolean type resulting from relational operators.
* Add opaque boolean

Added:
   sandbox/opaque/boost/opaque/boolean.hpp (contents, props changed)
Text files modified:
   sandbox/opaque/boost/opaque/combined_operators.hpp | 182 +++++++++++++++++++++++----------------
   sandbox/opaque/boost/opaque/opaque.hpp | 1
   sandbox/opaque/boost/opaque/operators.hpp | 68 ++++++++------
   3 files changed, 147 insertions(+), 104 deletions(-)

Added: sandbox/opaque/boost/opaque/boolean.hpp
==============================================================================
--- (empty file)
+++ sandbox/opaque/boost/opaque/boolean.hpp 2010-09-30 16:28:36 EDT (Thu, 30 Sep 2010)
@@ -0,0 +1,43 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2010.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/opaque for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_OPAQUE_BOOLEAN_HPP
+#define BOOST_OPAQUE_BOOLEAN_HPP
+
+
+namespace boost {
+namespace opaque {
+
+ class boolean {
+ bool val_;
+ typedef bool boolean::*unspecified_bool_type;
+ public:
+ explicit boolean(const bool b) : val_(b) {}
+
+ operator unspecified_bool_type() const
+ { return val_ ? &boolean::val_ : 0; }
+ boolean operator!() const {
+ return boolean(!val_);
+ }
+ boolean operator&&(boolean rhs) const {
+ return boolean(val_&&rhs.val_);
+ }
+ boolean operator||(boolean rhs) const {
+ return boolean(val_||rhs.val_);
+ }
+ };
+ const boolean true_=boolean(true);
+ const boolean false_=boolean(false);
+}
+}
+
+#endif

Modified: sandbox/opaque/boost/opaque/combined_operators.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/combined_operators.hpp (original)
+++ sandbox/opaque/boost/opaque/combined_operators.hpp 2010-09-30 16:28:36 EDT (Thu, 30 Sep 2010)
@@ -20,38 +20,40 @@
 
 namespace opaque {
 
-#define BOOST_OPAQUE_EQUALITY_COMPARABLE1(Final) \
- BOOST_OPAQUE_USING_EQUAL(Final) \
- BOOST_OPAQUE_USING_NOT_EQUAL(Final)
+#define BOOST_OPAQUE_EQUALITY_COMPARABLE1(Final,Bool) \
+ BOOST_OPAQUE_USING_EQUAL(Final,Bool) \
+ BOOST_OPAQUE_USING_NOT_EQUAL(Final,Bool)
     
+ template <typename Bool=bool>
     struct using_equality_comparable1 {
         template <typename Final, typename UT, typename Base>
         struct type : Base {
- BOOST_OPAQUE_EQUALITY_COMPARABLE1(Final)
+ BOOST_OPAQUE_EQUALITY_COMPARABLE1(Final,Bool)
         };
     };
 
- template <typename Final, typename Base>
+ template <typename Final, typename Base, typename Bool=bool>
     struct equality_comparable1 : Base {
- BOOST_OPAQUE_EQUALITY_COMPARABLE1(Final)
+ BOOST_OPAQUE_EQUALITY_COMPARABLE1(Final,Bool)
     };
 
-#define BOOST_OPAQUE_LESS_THAN_COMPARABLE1(Final) \
- BOOST_OPAQUE_USING_LESS_THAN(Final) \
- BOOST_OPAQUE_USING_LESS_THAN_EQUAL(Final) \
- BOOST_OPAQUE_USING_GREATER_THAN(Final) \
- BOOST_OPAQUE_USING_GREATER_THAN_EQUAL(Final)
+#define BOOST_OPAQUE_LESS_THAN_COMPARABLE1(Final,Bool) \
+ BOOST_OPAQUE_USING_LESS_THAN(Final,Bool) \
+ BOOST_OPAQUE_USING_LESS_THAN_EQUAL(Final,Bool) \
+ BOOST_OPAQUE_USING_GREATER_THAN(Final,Bool) \
+ BOOST_OPAQUE_USING_GREATER_THAN_EQUAL(Final,Bool)
 
+ template <typename Bool=bool>
     struct using_less_than_comparable1 {
         template <typename Final, typename UT, typename Base>
         struct type : Base {
- BOOST_OPAQUE_LESS_THAN_COMPARABLE1(Final)
+ BOOST_OPAQUE_LESS_THAN_COMPARABLE1(Final,Bool)
         };
     };
     
- template <typename Final, typename Base>
+ template <typename Final, typename Base, typename Bool=bool>
     struct less_than_comparable1 : Base {
- BOOST_OPAQUE_LESS_THAN_COMPARABLE1(Final)
+ BOOST_OPAQUE_LESS_THAN_COMPARABLE1(Final,Bool)
     };
 
 
@@ -114,7 +116,7 @@
     struct using_dividable1 {
         template <typename Final, typename UT, typename Base>
         struct type : Base {
- BOOST_OPAQUE_MULTIPLIABLE1(Final)
+ BOOST_OPAQUE_DIVIDABLE1(Final)
         };
     };
         
@@ -165,154 +167,188 @@
     template <typename Final, typename Base>
     struct partially_ordered1 : boost::partially_ordered1<Final, ope::less_than<Final, Base> > {};
 
+#define BOOST_OPAQUE_TOTALY_ORDERED1(Final,Bool) \
+ BOOST_OPAQUE_EQUALITY_COMPARABLE1(Final,Bool) \
+ BOOST_OPAQUE_LESS_THAN_COMPARABLE1(Final,Bool)
 
- template <class T, class UT, class B = base_new_type >
- struct totally_ordered1
- : opaque::less_than_comparable1<T
- //~ , opaque::equality_comparable1<T, B
- , opaque::using_equality_comparable1::template type<T, UT, B
- > > {};
+ template <typename Bool=bool>
+ struct using_totally_ordered1 {
+ template <typename Final, typename UT, typename Base>
+ struct type : Base {
+ BOOST_OPAQUE_TOTALY_ORDERED1(Final,Bool)
+ };
+ };
+
+ template <class Final, class UT, class Base, typename Bool=bool >
+ struct totally_ordered1 : Base
+ {
+ BOOST_OPAQUE_TOTALY_ORDERED1(Final,Bool)
+ };
 
- //~ template <class T, class U, class B = base_new_type >
+ //~ template <class T, class U, class Base = base_new_type >
     //~ struct additive2
         //~ : opaque::addable2<T, U
- //~ , opaque::subtractable2<T, U, B
+ //~ , opaque::subtractable2<T, U, Base
           //~ > > {};
 
- template <class T, class B = base_new_type >
- struct additive1
- : opaque::addable1<T
- , opaque::subtractable1<T, B
- > > {};
+ #define BOOST_OPAQUE_ADDITIVE1(Final) \
+ BOOST_OPAQUE_ADDABLE1(Final) \
+ BOOST_OPAQUE_SUBTRACTABLE1(Final)
+
 
- //~ template <class T, class U, class B = base_new_type >
+ struct using_additive1 {
+ template <typename Final, typename UT, typename Base>
+ struct type : Base {
+ BOOST_OPAQUE_ADDITIVE1(Final)
+ };
+ };
+
+ template <class Final, class Base = base_new_type >
+ struct additive1 : Base
+ {
+ BOOST_OPAQUE_ADDITIVE1(Final)
+ };
+
+ //~ template <class T, class U, class Base = base_new_type >
     //~ struct multiplicative2
         //~ : opaque::multipliable2<T, U
- //~ , opaque::dividable2<T, U, B
+ //~ , opaque::dividable2<T, U, Base
           //~ > > {};
 
- template <class T, class B = base_new_type >
- struct multiplicative1
- : opaque::multipliable1<T
- , opaque::dividable1<T, B
- > > {};
+ #define BOOST_OPAQUE_MULTIPLICATIVE1(Final) \
+ BOOST_OPAQUE_MULTIPLIABLE1(Final) \
+ BOOST_OPAQUE_DIVIDABLE1(Final)
+
+
+ struct using_multiplicative1 {
+ template <typename Final, typename UT, typename Base>
+ struct type : Base {
+ BOOST_OPAQUE_MULTIPLICATIVE1(Final)
+ };
+ };
+
+ template <class Final, class Base = base_new_type >
+ struct multiplicative1 : Base
+ {
+ BOOST_OPAQUE_MULTIPLICATIVE1(Final)
+ };
 
- //~ template <class T, class U, class B = base_new_type >
+ //~ template <class T, class U, class Base = base_new_type >
     //~ struct integer_multiplicative2
         //~ : opaque::multiplicative2<T, U
- //~ , opaque::modable2<T, U, B
+ //~ , opaque::modable2<T, U, Base
           //~ > > {};
 
- template <class T, class B = base_new_type >
+ template <class T, class Base = base_new_type >
     struct integer_multiplicative1
         : opaque::multiplicative1<T
- , opaque::modable1<T, B
+ , opaque::modable1<T, Base
> > {};
 
- //~ template <class T, class U, class B = base_new_type >
+ //~ template <class T, class U, class Base = base_new_type >
     //~ struct arithmetic2
         //~ : opaque::additive2<T, U
- //~ , opaque::multiplicative2<T, U, B
+ //~ , opaque::multiplicative2<T, U, Base
           //~ > > {};
 
- template <class T, class B = base_new_type >
+ template <class T, class Base = base_new_type >
     struct arithmetic1
         : opaque::additive1<T
- , opaque::multiplicative1<T, B
+ , opaque::multiplicative1<T, Base
> > {};
 
- //~ template <class T, class U, class B = base_new_type >
+ //~ template <class T, class U, class Base = base_new_type >
     //~ struct integer_arithmetic2
         //~ : additive2<T, U
- //~ , integer_multiplicative2<T, U, B
+ //~ , integer_multiplicative2<T, U, Base
           //~ > > {};
 
- template <class T, class B = base_new_type >
+ template <class T, class Base = base_new_type >
     struct integer_arithmetic1
         : opaque::additive1<T
- , opaque::integer_multiplicative1<T, B
+ , opaque::integer_multiplicative1<T, Base
> > {};
 
- //~ template <class T, class U, class B = base_new_type >
+ //~ template <class T, class U, class Base = base_new_type >
     //~ struct bitwise2
         //~ : opaque::xorable2<T, U
         //~ , opaque::andable2<T, U
- //~ , opaque::orable2<T, U, B
+ //~ , opaque::orable2<T, U, Base
           //~ > > > {};
 
- template <class T, class B = base_new_type >
+ template <class T, class Base = base_new_type >
     struct bitwise1
         : opaque::xorable1<T
         , opaque::andable1<T
- , opaque::orable1<T, B
+ , opaque::orable1<T, Base
> > > {};
 
- template <class T, class B = base_new_type >
+ template <class T, class Base = base_new_type >
     struct unit_steppable
         : opaque::incrementable<T
- , opaque::decrementable<T, B
+ , opaque::decrementable<T, Base
> > {};
 
- //~ template <class T, class U, class B = base_new_type >
+ //~ template <class T, class U, class Base = base_new_type >
     //~ struct shiftable2
         //~ : opaque::left_shiftable2<T, U
- //~ , opaque::right_shiftable2<T, U, B
+ //~ , opaque::right_shiftable2<T, U, Base
           //~ > > {};
 
- template <class T, class B = base_new_type >
+ template <class T, class Base = base_new_type >
     struct shiftable1
         : opaque::left_shiftable1<T
- , opaque::right_shiftable1<T, B
+ , opaque::right_shiftable1<T, Base
> > {};
 
- //~ template <class T, class U, class B = base_new_type >
+ //~ template <class T, class U, class Base = base_new_type >
     //~ struct ring_operators2
         //~ : opaque::additive2<T, U
         //~ , opaque::subtractable2_left<T, U
- //~ , opaque::multipliable2<T, U, B
+ //~ , opaque::multipliable2<T, U, Base
           //~ > > > {};
 
- template <class T, class B = base_new_type >
+ template <class T, class Base = base_new_type >
     struct ring_operators1
         : opaque::additive1<T
- , opaque::multipliable1<T, B
+ , opaque::multipliable1<T, Base
> > {};
 
- //~ template <class T, class U, class B = base_new_type >
+ //~ template <class T, class U, class Base = base_new_type >
     //~ struct ordered_ring_operators2
         //~ : opaque::ring_operators2<T, U
- //~ , opaque::totally_ordered2<T, U, B
+ //~ , opaque::totally_ordered2<T, U, Base
           //~ > > {};
 
- template <class T, class UT, class B = base_new_type >
+ template <class T, class UT, class Base = base_new_type >
     struct ordered_ring_operators1
         : opaque::ring_operators1<T
- , opaque::totally_ordered1<T, UT, B
+ , opaque::totally_ordered1<T, UT, Base
> > {};
 
- //~ template <class T, class U, class B = base_new_type >
+ //~ template <class T, class U, class Base = base_new_type >
     //~ struct field_operators2
         //~ : opaque::ring_operators2<T, U
         //~ , opaque::dividable2<T, U
- //~ , opaque::dividable2_left<T, U, B
+ //~ , opaque::dividable2_left<T, U, Base
           //~ > > > {};
 
- template <class T, class B = base_new_type >
+ template <class T, class Base = base_new_type >
     struct field_operators1
         : opaque::ring_operators1<T
- , opaque::dividable1<T, B
+ , opaque::dividable1<T, Base
> > {};
 
- //~ template <class T, class U, class B = base_new_type >
+ //~ template <class T, class U, class Base = base_new_type >
     //~ struct ordered_field_operators2
         //~ : opaque::field_operators2<T, U
- //~ , opaque::totally_ordered2<T, U, B
+ //~ , opaque::totally_ordered2<T, U, Base
           //~ > > {};
 
- template <class T, class UT, class B = base_new_type >
+ template <class T, class UT, class Base = base_new_type >
     struct ordered_field_operators1
         : opaque::field_operators1<T
- , opaque::totally_ordered1<T, UT, B
+ , opaque::totally_ordered1<T, UT, Base
> > {};
 
 

Modified: sandbox/opaque/boost/opaque/opaque.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/opaque.hpp (original)
+++ sandbox/opaque/boost/opaque/opaque.hpp 2010-09-30 16:28:36 EDT (Thu, 30 Sep 2010)
@@ -20,6 +20,7 @@
 #include <boost/opaque/private_opaque_class.hpp>
 #include <boost/opaque/public_opaque_type.hpp>
 #include <boost/opaque/public_opaque_class.hpp>
+#include <boost/opaque/boolean.hpp>
 #include <boost/opaque/macros.hpp>
 
 #include <boost/mpl/bool.hpp>

Modified: sandbox/opaque/boost/opaque/operators.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/operators.hpp (original)
+++ sandbox/opaque/boost/opaque/operators.hpp 2010-09-30 16:28:36 EDT (Thu, 30 Sep 2010)
@@ -56,95 +56,101 @@
         };
     };
 
-#define BOOST_OPAQUE_USING_LESS_THAN(Final) \
+#define BOOST_OPAQUE_USING_LESS_THAN(Final, Bool) \
     public :\
- bool operator<(const Final& rhs) const { \
- return Final::underlying(this) < rhs.underlying();\
+ Bool operator<(const Final& rhs) const { \
+ return Bool(Final::underlying(this) < rhs.underlying());\
         }
 
- template <typename Final, typename Base>
+ template <typename Final, typename Base, typename Bool=bool>
     struct less_than : Base {
- BOOST_OPAQUE_USING_LESS_THAN(Final)
+ BOOST_OPAQUE_USING_LESS_THAN(Final, Bool)
     };
-
+
+ template <typename Bool=bool>
     struct using_less_than {
         template <typename Final, typename UT, typename Base>
         struct type: Base {
- BOOST_OPAQUE_USING_LESS_THAN(Final)
+ BOOST_OPAQUE_USING_LESS_THAN(Final,Bool)
         };
     };
 
-#define BOOST_OPAQUE_USING_LESS_THAN_EQUAL(Final) \
+#define BOOST_OPAQUE_USING_LESS_THAN_EQUAL(Final,Bool) \
     public :\
- bool operator<=(const Final& rhs) const { \
- return Final::underlying(this) <= rhs.underlying();\
+ Bool operator<=(const Final& rhs) const { \
+ return Bool(Final::underlying(this) <= rhs.underlying());\
         }
 
+ template <typename Bool=bool>
     struct using_less_than_equal {
         template <typename Final, typename UT, typename Base>
         struct type: Base {
- BOOST_OPAQUE_USING_LESS_THAN_EQUAL(Final)
+ BOOST_OPAQUE_USING_LESS_THAN_EQUAL(Final,Bool)
         };
     };
 
-#define BOOST_OPAQUE_USING_GREATER_THAN(Final) \
+#define BOOST_OPAQUE_USING_GREATER_THAN(Final,Bool) \
     public :\
- bool operator>(const Final& rhs) const { \
- return Final::underlying(this) > rhs.underlying();\
+ Bool operator>(const Final& rhs) const { \
+ return Bool(Final::underlying(this) > rhs.underlying());\
         }
 
+ template <typename Bool=bool>
     struct using_greater_than {
         template <typename Final, typename UT, typename Base>
         struct type: Base {
- BOOST_OPAQUE_USING_GREATER_THAN(Final)
+ BOOST_OPAQUE_USING_GREATER_THAN(Final,Bool)
         };
     };
 
-#define BOOST_OPAQUE_USING_GREATER_THAN_EQUAL(Final) \
+#define BOOST_OPAQUE_USING_GREATER_THAN_EQUAL(Final,Bool) \
     public :\
- bool operator>=(const Final& rhs) const { \
- return Final::underlying(this) >= rhs.underlying();\
+ Bool operator>=(const Final& rhs) const { \
+ return Bool(Final::underlying(this) >= rhs.underlying());\
         }
 
+ template <typename Bool=bool>
     struct using_greater_than_equal {
         template <typename Final, typename UT, typename Base>
         struct type: Base {
- BOOST_OPAQUE_USING_GREATER_THAN_EQUAL(Final)
+ BOOST_OPAQUE_USING_GREATER_THAN_EQUAL(Final,Bool)
         };
     };
 
-#define BOOST_OPAQUE_USING_EQUAL(Final) \
+#define BOOST_OPAQUE_USING_EQUAL(Final,Bool) \
     public :\
- bool operator==(const Final& rhs) const { \
- return Final::underlying(this) == rhs.underlying();\
+ Bool operator==(const Final& rhs) const { \
+ return Bool(Final::underlying(this) == rhs.underlying());\
         }
 
- template <typename Final, typename Base>
+ template <typename Final, typename Base, typename Bool=bool>
     struct equal : Base {
- BOOST_OPAQUE_USING_EQUAL(Final)
+ BOOST_OPAQUE_USING_EQUAL(Final,Bool)
     };
+ template <typename Bool=bool>
     struct using_equal {
         template <typename Final, typename UT, typename Base>
         struct type: Base {
- BOOST_OPAQUE_USING_EQUAL(Final)
+ BOOST_OPAQUE_USING_EQUAL(Final,Bool)
         };
     };
 
-#define BOOST_OPAQUE_USING_NOT_EQUAL(Final) \
+#define BOOST_OPAQUE_USING_NOT_EQUAL(Final,Bool) \
     public :\
- bool operator!=(const Final& rhs) const { \
- return Final::underlying(this) != rhs.underlying();\
+ Bool operator!=(const Final& rhs) const { \
+ return Bool(Final::underlying(this) != rhs.underlying());\
         }
 
 
- template <typename Final, typename Base>
+ template <typename Final, typename Base, typename Bool=bool>
     struct not_equal : Base {
- BOOST_OPAQUE_USING_NOT_EQUAL(Final)
+ BOOST_OPAQUE_USING_NOT_EQUAL(Final,Bool)
     };
+ template <typename Bool=bool>
     struct using_not_equal {
         template <typename Final, typename UT, typename Base>
         struct type: Base {
- BOOST_OPAQUE_USING_NOT_EQUAL(Final)
+ BOOST_OPAQUE_USING_NOT_EQUAL(Final,Bool)
         };
     };
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk