Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65686 - sandbox/opaque/boost/opaque
From: vicente.botet_at_[hidden]
Date: 2010-09-29 15:51:30


Author: viboes
Date: 2010-09-29 15:51:27 EDT (Wed, 29 Sep 2010)
New Revision: 65686
URL: http://svn.boost.org/trac/boost/changeset/65686

Log:
Opaque:
* Continue defining macros so inheritance is avoided.
Text files modified:
   sandbox/opaque/boost/opaque/combined_operators.hpp | 105 +++++++++++++++++-
   sandbox/opaque/boost/opaque/operators.hpp | 215 ++++++++++++++++++++++++++++++---------
   2 files changed, 261 insertions(+), 59 deletions(-)

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-29 15:51:27 EDT (Wed, 29 Sep 2010)
@@ -20,12 +20,20 @@
 
 namespace opaque {
 
- template <typename Final, typename Base>
- struct equality_comparable1 : boost::equality_comparable1<Final, ope::equal<Final, Base> > {};
-
+#define BOOST_OPAQUE_EQUALITY_COMPARABLE1(Final) \
+ BOOST_OPAQUE_USING_EQUAL(Final) \
+ BOOST_OPAQUE_USING_NOT_EQUAL(Final)
+
     struct using_equality_comparable1 {
         template <typename Final, typename UT, typename Base>
- struct type : boost::equality_comparable1<Final, ope::equal<Final, Base> > {};
+ struct type : Base {
+ BOOST_OPAQUE_EQUALITY_COMPARABLE1(Final)
+ };
+ };
+
+ template <typename Final, typename Base>
+ struct equality_comparable1 : Base {
+ BOOST_OPAQUE_EQUALITY_COMPARABLE1(Final)
     };
 
 #define BOOST_OPAQUE_LESS_THAN_COMPARABLE1(Final) \
@@ -34,25 +42,104 @@
         BOOST_OPAQUE_USING_GREATER_THAN(Final) \
         BOOST_OPAQUE_USING_GREATER_THAN_EQUAL(Final)
 
+ struct using_less_than_comparable1 {
+ template <typename Final, typename UT, typename Base>
+ struct type : Base {
+ BOOST_OPAQUE_LESS_THAN_COMPARABLE1(Final)
+ };
+ };
+
     template <typename Final, typename Base>
     struct less_than_comparable1 : Base {
         BOOST_OPAQUE_LESS_THAN_COMPARABLE1(Final)
     };
 
+
+#define BOOST_OPAQUE_ADDABLE1(Final) \
+ BOOST_OPAQUE_USING_PLUS_ASSIGN(Final) \
+ BOOST_OPAQUE_USING_PLUS(Final)
+
+ struct using_addable1 {
+ template <typename Final, typename UT, typename Base>
+ struct type : Base {
+ BOOST_OPAQUE_ADDABLE1(Final)
+ };
+ };
+
+
     template <typename Final, typename Base>
- struct addable1 : boost::addable1<Final, ope::plus_assign<Final, Base> > {};
+ struct addable1 : Base {
+ BOOST_OPAQUE_ADDABLE1(Final)
+ };
+
+#define BOOST_OPAQUE_SUBTRACTABLE1(Final) \
+ BOOST_OPAQUE_USING_MINUS_ASSIGN(Final) \
+ BOOST_OPAQUE_USING_MINUS(Final)
 
+ struct using_subtractable1 {
+ template <typename Final, typename UT, typename Base>
+ struct type : Base {
+ BOOST_OPAQUE_SUBTRACTABLE1(Final)
+ };
+ };
+
+
     template <typename Final, typename Base>
- struct subtractable1 : boost::subtractable1<Final, ope::minus_assign<Final, Base> > {};
+ struct subtractable1 : Base
+ {
+ BOOST_OPAQUE_SUBTRACTABLE1(Final)
+ };
+
+
+#define BOOST_OPAQUE_MULTIPLIABLE1(Final) \
+ BOOST_OPAQUE_USING_MULTIPLY_ASSIGN(Final) \
+ BOOST_OPAQUE_USING_MULTIPLY(Final)
 
+ struct using_multipliable1 {
+ template <typename Final, typename UT, typename Base>
+ struct type : Base {
+ BOOST_OPAQUE_MULTIPLIABLE1(Final)
+ };
+ };
+
     template <typename Final, typename Base>
- struct multipliable1 : boost::multipliable1<Final, ope::multiply_assign<Final, Base> > {};
+ struct multipliable1 : Base {
+ BOOST_OPAQUE_MULTIPLIABLE1(Final)
+ };
+
+#define BOOST_OPAQUE_DIVIDABLE1(Final) \
+ BOOST_OPAQUE_USING_DIVIDE_ASSIGN(Final) \
+ BOOST_OPAQUE_USING_DIVIDE(Final)
 
+ struct using_dividable1 {
+ template <typename Final, typename UT, typename Base>
+ struct type : Base {
+ BOOST_OPAQUE_MULTIPLIABLE1(Final)
+ };
+ };
+
     template <typename Final, typename Base>
- struct dividable1 : boost::dividable1<Final, ope::divide_assign<Final, Base> > {};
+ struct dividable1
+ //~ : boost::dividable1<Final, ope::divide_assign<Final, Base> >
+ : Base
+ {
+ BOOST_OPAQUE_DIVIDABLE1(Final)
+ };
+
+#define BOOST_OPAQUE_MODABLE1(Final) \
+ BOOST_OPAQUE_USING_MODULUS_ASSIGN(Final) \
+ BOOST_OPAQUE_USING_MODULUS(Final)
 
+ struct using_modable1 {
+ template <typename Final, typename UT, typename Base>
+ struct type : Base {
+ BOOST_OPAQUE_MODABLE1(Final)
+ };
+ };
     template <typename Final, typename Base>
- struct modable1 : boost::modable1<Final, ope::modulus_assign<Final, Base> > {};
+ struct modable1 : Base {
+ BOOST_OPAQUE_MODABLE1(Final)
+ };
 
     template <typename Final, typename Base>
     struct xorable1 : boost::xorable1<Final, ope::bitwise_xor_assign<Final, Base> > {};

Modified: sandbox/opaque/boost/opaque/operators.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/operators.hpp (original)
+++ sandbox/opaque/boost/opaque/operators.hpp 2010-09-29 15:51:27 EDT (Wed, 29 Sep 2010)
@@ -44,7 +44,7 @@
     };
 
 #define BOOST_OPAQUE_USING_CONVERSION(Final,UT) \
- public: \
+ public: \
             operator UT() const{ \
                 return Final::underlying(this); \
             }
@@ -57,7 +57,7 @@
     };
 
 #define BOOST_OPAQUE_USING_LESS_THAN(Final) \
- public :\
+ public :\
         bool operator<(const Final& rhs) const { \
             return Final::underlying(this) < rhs.underlying();\
         }
@@ -75,7 +75,7 @@
     };
 
 #define BOOST_OPAQUE_USING_LESS_THAN_EQUAL(Final) \
- public :\
+ public :\
         bool operator<=(const Final& rhs) const { \
             return Final::underlying(this) <= rhs.underlying();\
         }
@@ -88,7 +88,7 @@
     };
 
 #define BOOST_OPAQUE_USING_GREATER_THAN(Final) \
- public :\
+ public :\
         bool operator>(const Final& rhs) const { \
             return Final::underlying(this) > rhs.underlying();\
         }
@@ -101,7 +101,7 @@
     };
 
 #define BOOST_OPAQUE_USING_GREATER_THAN_EQUAL(Final) \
- public :\
+ public :\
         bool operator>=(const Final& rhs) const { \
             return Final::underlying(this) >= rhs.underlying();\
         }
@@ -114,16 +114,14 @@
     };
 
 #define BOOST_OPAQUE_USING_EQUAL(Final) \
- public :\
+ public :\
         bool operator==(const Final& rhs) const { \
             return Final::underlying(this) == rhs.underlying();\
         }
 
     template <typename Final, typename Base>
     struct equal : Base {
- friend bool operator==(const Final& x, const Final& y) {
- return x.underlying() == y.underlying();
- }
+ BOOST_OPAQUE_USING_EQUAL(Final)
     };
     struct using_equal {
         template <typename Final, typename UT, typename Base>
@@ -133,7 +131,7 @@
     };
 
 #define BOOST_OPAQUE_USING_NOT_EQUAL(Final) \
- public :\
+ public :\
         bool operator!=(const Final& rhs) const { \
             return Final::underlying(this) != rhs.underlying();\
         }
@@ -141,9 +139,7 @@
 
     template <typename Final, typename Base>
     struct not_equal : Base {
- friend bool operator!=(const Final& x, const Final& y) {
- return x.underlying() != y.underlying();
- }
+ BOOST_OPAQUE_USING_NOT_EQUAL(Final)
     };
     struct using_not_equal {
         template <typename Final, typename UT, typename Base>
@@ -153,7 +149,7 @@
     };
 
 #define BOOST_OPAQUE_USING_PLUS_ASSIGN(Final) \
- public :\
+ public :\
         Final& operator+=(const Final& rhs) { \
             Final::underlying(this) += rhs.underlying();\
             return Final::final(this); \
@@ -171,7 +167,7 @@
     };
 
 #define BOOST_OPAQUE_USING_MINUS_ASSIGN(Final) \
- public :\
+ public :\
         Final& operator-=(const Final& rhs) { \
             Final::underlying(this) -= rhs.underlying();\
             return Final::final(this); \
@@ -189,7 +185,7 @@
     };
 
 #define BOOST_OPAQUE_USING_MULTIPLY_ASSIGN(Final) \
- public :\
+ public :\
         Final& operator*=(const Final& rhs) { \
             Final::underlying(this) *= rhs.underlying();\
             return Final::final(this); \
@@ -207,7 +203,7 @@
     };
 
 #define BOOST_OPAQUE_USING_DIVIDE_ASSIGN(Final) \
- public :\
+ public :\
         Final& operator/=(const Final& rhs) { \
             Final::underlying(this) /= rhs.underlying();\
             return Final::final(this); \
@@ -225,7 +221,7 @@
     };
 
 #define BOOST_OPAQUE_USING_MODULUS_ASSIGN(Final) \
- public :\
+ public :\
         Final& operator%=(const Final& rhs) { \
             Final::underlying(this) %= rhs.underlying();\
             return Final::final(this); \
@@ -243,7 +239,7 @@
     };
 
 #define BOOST_OPAQUE_USING_BITWISE_XOR_ASSIGN(Final) \
- public :\
+ public :\
         Final& operator^=(const Final& rhs) { \
             Final::underlying(this) ^= rhs.underlying();\
             return Final::final(this); \
@@ -261,7 +257,7 @@
     };
 
 #define BOOST_OPAQUE_USING_BITWISE_AND_ASSIGN(Final) \
- public :\
+ public :\
         Final& operator&=(const Final& rhs) { \
             Final::underlying(this) &= rhs.underlying();\
             return Final::final(this); \
@@ -279,7 +275,7 @@
     };
 
 #define BOOST_OPAQUE_USING_BITWISE_OR_ASSIGN(Final) \
- public :\
+ public :\
         Final& operator|=(const Final& rhs) { \
             Final::underlying(this) |= rhs.underlying();\
             return Final::final(this); \
@@ -297,7 +293,7 @@
     };
 
 #define BOOST_OPAQUE_USING_LEFT_SHIFT_ASSIGN(Final) \
- public :\
+ public :\
         Final& operator<<=(const Final& rhs) { \
             Final::underlying(this) <<= rhs.underlying();\
             return Final::final(this); \
@@ -315,7 +311,7 @@
     };
 
 #define BOOST_OPAQUE_USING_RIGHT_SHIFT_ASSIGN(Final) \
- public :\
+ public :\
         Final& operator>>=(const Final& rhs) { \
             Final::underlying(this) >>= rhs.underlying();\
             return Final::final(this); \
@@ -334,7 +330,7 @@
     // Unary operators
 
 #define BOOST_OPAQUE_USING_LOGICAL_NOT(Final) \
- public :\
+ public :\
         bool operator!() const { \
             return !Final::underlying(this);\
         }
@@ -351,24 +347,57 @@
         BOOST_OPAQUE_USING_LOGICAL_NOT(Final)
     };
 
+#define BOOST_OPAQUE_USING_UNARY_PLUS(Final) \
+ public :\
+ Final operator+() const { \
+ return Final(+(Final::underlying(this)));\
+ }
+
+ struct using_unary_plus {
+ template <typename Final, typename UT, typename Base>
+ struct type: Base {
+ BOOST_OPAQUE_USING_UNARY_PLUS(Final)
+ };
+ };
+
     template <typename Final, typename Base>
     struct unary_plus : Base {
- friend Final operator+(Final const& x) {
- return x;
+ BOOST_OPAQUE_USING_UNARY_PLUS(Final)
+ };
+
+#define BOOST_OPAQUE_USING_UNARY_MINUS(Final) \
+ public :\
+ Final operator-() const { \
+ return Final(-(Final::underlying(this))); \
         }
+
+ struct using_unary_minus {
+ template <typename Final, typename UT, typename Base>
+ struct type: Base {
+ BOOST_OPAQUE_USING_UNARY_MINUS(Final)
+ };
     };
+
     template <typename Final, typename Base>
     struct unary_minus : Base {
- friend Final operator-(Final const& x) {
- return Final(-(x.underlying()));
- }
+ BOOST_OPAQUE_USING_UNARY_MINUS(Final)
     };
 
+#define BOOST_OPAQUE_USING_BITWISE_NOT(Final) \
+ public :\
+ Final operator~() const { \
+ return Final(~(Final::underlying(this))); \
+ }
+
+ struct using_bitwise_not {
+ template <typename Final, typename UT, typename Base>
+ struct type: Base {
+ BOOST_OPAQUE_USING_BITWISE_NOT(Final)
+ };
+ };
     template <typename Final, typename Base>
     struct bitwise_not : Base {
- friend Final operator~(Final const& x) {
- return Final(~(x.underlying()));
- }
+ BOOST_OPAQUE_USING_BITWISE_NOT(Final)
     };
 
     //~ template <typename Final, typename Base>
@@ -400,40 +429,126 @@
     //~ };
 
     // Increment and decrement
+#define BOOST_OPAQUE_USING_PRE_INCREMENT(Final) \
+ public :\
+ Final& operator++() { \
+ ++Final::underlying(this); \
+ return Final::final(this); \
+ }
+
+ struct using_pre_increment {
+ template <typename Final, typename UT, typename Base>
+ struct type: Base {
+ BOOST_OPAQUE_USING_PRE_INCREMENT(Final)
+ };
+ };
     template <typename Final, typename Base>
     struct pre_increment : Base {
- friend Final& operator++(Final& x) {
- ++x.underlying();
- return x;
- }
+ BOOST_OPAQUE_USING_PRE_INCREMENT(Final)
     };
 
+#define BOOST_OPAQUE_USING_PRE_DECREMENT(Final) \
+ public :\
+ Final& operator--() { \
+ --Final::underlying(this); \
+ return Final::final(this); \
+ }
+
+ struct using_pre_decrement {
+ template <typename Final, typename UT, typename Base>
+ struct type: Base {
+ BOOST_OPAQUE_USING_PRE_DECREMENT(Final)
+ };
+ };
     template <typename Final, typename Base>
     struct pre_decrement : Base {
- friend Final& operator--(Final& x) {
- --x.underlying();
- return x;
- }
+ BOOST_OPAQUE_USING_PRE_DECREMENT(Final)
     };
 
+#define BOOST_OPAQUE_USING_POST_INCREMENT(Final) \
+ public :\
+ Final& operator--() { \
+ typename Final::underlying_type nrv(*this); \
+ Final::underlying(this)++; \
+ return nrv; \
+ }
+
+ struct using_post_increment {
+ template <typename Final, typename UT, typename Base>
+ struct type: Base {
+ BOOST_OPAQUE_USING_POST_INCREMENT(Final)
+ };
+ };
     template <typename Final, typename Base>
     struct post_increment : Base {
- friend Final operator++(Final& x, int) {
- typename Final::underlying_type nrv(x);
- x.underlying()++;
- return nrv;
- }
+ BOOST_OPAQUE_USING_POST_INCREMENT(Final)
     };
 
+#define BOOST_OPAQUE_USING_POST_DECREMENT(Final) \
+ public :\
+ Final& operator--() { \
+ typename Final::underlying_type nrv(*this); \
+ Final::underlying(this)--; \
+ return nrv; \
+ }
+
+ struct using_post_decrement {
+ template <typename Final, typename UT, typename Base>
+ struct type: Base {
+ BOOST_OPAQUE_USING_POST_DECREMENT(Final)
+ };
+ };
     template <typename Final, typename Base>
     struct post_decrement : Base {
- friend Final operator--(Final& x, int) {
- typename Final::underlying_type nrv(x);
- x.underlying()--;
- return nrv;
- }
+ BOOST_OPAQUE_USING_POST_DECREMENT(Final)
     };
+
+#if 0
+// I don't know why this doesn't works :(
+
+#define BOOST_OPAQUE_USING_PLUS(Final) \
+ public :\
+ Final operator+(const Final& rhs) const { \
+ return Final(Final::underlying(this) + rhs.underlying()); \
+ }
+
+#define BOOST_OPAQUE_USING_MINUS(Final) \
+ public :\
+ Final operator-(const Final& rhs) const { \
+ return Final(Final::underlying(this) - rhs.underlying()); \
+ }
+#else
+#define BOOST_OPAQUE_USING_PLUS(Final) \
+ public :\
+ friend Final operator+(const Final& lhs, const Final& rhs) { \
+ return Final(lhs.underlying() + rhs.underlying()); \
+ }
+#define BOOST_OPAQUE_USING_MINUS(Final) \
+ public :\
+ friend Final operator-(const Final& lhs, const Final& rhs) { \
+ return Final(lhs.underlying() - rhs.underlying()); \
+ }
+#endif
+
+#define BOOST_OPAQUE_USING_MULTIPLY(Final) \
+ public :\
+ Final operator*(const Final& rhs) const { \
+ return Final(Final::underlying(this) * rhs.underlying()); \
+ }
+
+#define BOOST_OPAQUE_USING_DIVIDE(Final) \
+ public :\
+ Final operator/(const Final& rhs) const { \
+ return Final(Final::underlying(this) / rhs.underlying()); \
+ }
+
+#define BOOST_OPAQUE_USING_MODULUS(Final) \
+ public :\
+ Final operator%(const Final& rhs) const { \
+ return Final(Final::underlying(this) % rhs.underlying()); \
+ }
 
+
 }
 
 }


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