Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65652 - sandbox/opaque/boost/opaque
From: vicente.botet_at_[hidden]
Date: 2010-09-28 16:15:39


Author: viboes
Date: 2010-09-28 16:15:32 EDT (Tue, 28 Sep 2010)
New Revision: 65652
URL: http://svn.boost.org/trac/boost/changeset/65652

Log:
Opaque:
* Extract transitive_substituable and generalize it so it can be used also with new_type
* Start defining macros so inheritance is avoided.

Added:
   sandbox/opaque/boost/opaque/transitive_substituable.hpp (contents, props changed)
Text files modified:
   sandbox/opaque/boost/opaque/combined_operators.hpp | 47 ++++++++++++--------
   sandbox/opaque/boost/opaque/opaque.hpp | 1
   sandbox/opaque/boost/opaque/operators.hpp | 90 ++++++++++++++++++++++++---------------
   sandbox/opaque/boost/opaque/private_opaque_class.hpp | 1
   sandbox/opaque/boost/opaque/public_opaque_class.hpp | 31 +------------
   5 files changed, 86 insertions(+), 84 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-28 16:15:32 EDT (Tue, 28 Sep 2010)
@@ -13,7 +13,6 @@
 #ifndef BOOST_OPAQUE_COMBINED_OPERATORS_HPP
 #define BOOST_OPAQUE_COMBINED_OPERATORS_HPP
 
-#include <boost/opaque/new_type.hpp>
 #include <boost/operators.hpp>
 #include <boost/opaque/operators.hpp>
 
@@ -21,55 +20,63 @@
 
 namespace opaque {
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct equality_comparable1 : boost::equality_comparable1<Final, ope::equal<Final, Base> > {};
 
     struct using_equality_comparable1 {
- template <typename Final, typename UT, typename Base=base_new_type>
+ template <typename Final, typename UT, typename Base>
         struct type : boost::equality_comparable1<Final, ope::equal<Final, Base> > {};
     };
 
- template <typename Final, typename Base=base_new_type>
- struct less_than_comparable1 : boost::less_than_comparable1<Final, ope::less_than<Final, Base> > {};
+#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)
+
+ template <typename Final, typename Base>
+ struct less_than_comparable1 : Base {
+ BOOST_OPAQUE_LESS_THAN_COMPARABLE1(Final)
+ };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct addable1 : boost::addable1<Final, ope::plus_assign<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct subtractable1 : boost::subtractable1<Final, ope::minus_assign<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct multipliable1 : boost::multipliable1<Final, ope::multiply_assign<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct dividable1 : boost::dividable1<Final, ope::divide_assign<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct modable1 : boost::modable1<Final, ope::modulus_assign<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct xorable1 : boost::xorable1<Final, ope::bitwise_xor_assign<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct andable1 : boost::andable1<Final, ope::bitwise_and_assign<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct orable1 : boost::orable1<Final, ope::bitwise_or_assign<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct incrementable : boost::incrementable<Final, ope::pre_increment<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct decrementable : boost::decrementable<Final, ope::pre_decrement<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct left_shiftable1 : boost::left_shiftable1<Final, ope::left_shift_assign<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct right_shiftable1 : boost::right_shiftable1<Final, ope::right_shift_assign<Final, Base> > {};
 
- template <typename Final, typename Base=base_new_type>
- struct partially_ordered1 : boost::less_than_comparable1<Final, ope::less_than<Final, Base> > {};
+ template <typename Final, typename Base>
+ struct partially_ordered1 : boost::partially_ordered1<Final, ope::less_than<Final, Base> > {};
 
 
     template <class T, class UT, class B = base_new_type >
@@ -226,7 +233,7 @@
 }
     template <typename T>
     struct inherited_from_undelying {
- template <typename Final, typename UT, typename Base=base_new_type>
+ template <typename Final, typename UT, typename Base>
             struct type :
                 opaque::totally_ordered1< Final, T
                 , opaque::integer_arithmetic1< Final

Modified: sandbox/opaque/boost/opaque/opaque.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/opaque.hpp (original)
+++ sandbox/opaque/boost/opaque/opaque.hpp 2010-09-28 16:15:32 EDT (Tue, 28 Sep 2010)
@@ -16,7 +16,6 @@
 #include <boost/opaque/new_type.hpp>
 #include <boost/opaque/new_class.hpp>
 #include <boost/opaque/operators.hpp>
-#include <boost/opaque/opaque_type.hpp>
 #include <boost/opaque/private_opaque_type.hpp>
 #include <boost/opaque/private_opaque_class.hpp>
 #include <boost/opaque/public_opaque_type.hpp>

Modified: sandbox/opaque/boost/opaque/operators.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/operators.hpp (original)
+++ sandbox/opaque/boost/opaque/operators.hpp 2010-09-28 16:15:32 EDT (Tue, 28 Sep 2010)
@@ -13,54 +13,76 @@
 #ifndef BOOST_OPAQUE_OPERATORS_HPP
 #define BOOST_OPAQUE_OPERATORS_HPP
 
-#include <boost/opaque/new_type.hpp>
+//~ #include <boost/opaque/new_type.hpp>
 #include <boost/operators.hpp>
 
 namespace boost {
 
 namespace opaque {
 namespace ope {
- template <typename Base=base_new_type>
+ template <typename Base>
     struct copy_delete : Base {
     private: // emphasize the following members are private
         copy_delete( const copy_delete & );
     };
 
- template <typename Base=base_new_type>
+ template <typename Base>
     struct assign_delete : Base {
     private: // emphasize the following members are private
             assign_delete& operator=(assign_delete const&);
     };
 
- template <typename UT, typename Base=base_new_type>
+ template <typename UT, typename Base>
     struct conversion : Base {
         operator UT() const{
                 return this->underlying();
         }
     };
 
- template <typename Final, typename Base=base_new_type>
- struct less_than : Base {
- friend bool operator<(const Final& x, const Final& y) {
- return x.underlying() < y.underlying();
+#define BOOST_OPAQUE_USING_LESS_THAN(Final) \
+ public :\
+ bool operator<(const Final& rhs) const { \
+ return Final::final(this).underlying() < rhs.underlying();\
+ }
+
+#define BOOST_OPAQUE_USING_LESS_THAN_EQUAL(Final) \
+ public :\
+ bool operator<=(const Final& rhs) const { \
+ return Final::final(this).underlying() <= rhs.underlying();\
+ }
+
+#define BOOST_OPAQUE_USING_GREATER_THAN(Final) \
+ public :\
+ bool operator>(const Final& rhs) const { \
+ return Final::final(this).underlying() > rhs.underlying();\
         }
+
+#define BOOST_OPAQUE_USING_GREATER_THAN_EQUAL(Final) \
+ public :\
+ bool operator>=(const Final& rhs) const { \
+ return Final::final(this).underlying() >= rhs.underlying();\
+ }
+
+ template <typename Final, typename Base>
+ struct less_than : Base {
+ BOOST_OPAQUE_USING_LESS_THAN(Final)
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct equal : Base {
         friend bool operator==(const Final& x, const Final& y) {
             return x.underlying() == y.underlying();
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct not_equal : Base {
         friend bool operator!=(const Final& x, const Final& y) {
             return x.underlying() != y.underlying();
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct plus_assign : Base {
         friend Final& operator+=(Final& x, const Final& y) {
             x.underlying() += y.underlying();
@@ -68,7 +90,7 @@
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct minus_assign : Base {
         friend Final& operator-=(Final& x, const Final& y) {
             x.underlying() -= y.underlying();
@@ -76,7 +98,7 @@
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct multiply_assign : Base {
         friend Final& operator*=(Final& x, const Final& y) {
             x.underlying() *= y.underlying();
@@ -84,7 +106,7 @@
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct divide_assign : Base {
         friend Final& operator/=(Final& x, const Final& y) {
             x.underlying() /= y.underlying();
@@ -92,7 +114,7 @@
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct modulus_assign : Base {
         friend Final& operator%=(Final& x, const Final& y) {
             x.underlying() %= y.underlying();
@@ -100,7 +122,7 @@
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct bitwise_xor_assign : Base {
         friend Final& operator^=(Final& x, const Final& y) {
             x.underlying() ^= y.underlying();
@@ -108,7 +130,7 @@
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct bitwise_and_assign : Base {
         friend Final& operator&=(Final& x, const Final& y) {
             x.underlying() &= y.underlying();
@@ -116,21 +138,21 @@
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct bitwise_or_assign : Base {
         friend Final& operator|=(Final& x, const Final& y) {
             x.underlying() |= y.underlying();
             return x;
         }
     };
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct left_shift_assign : Base {
         friend Final& operator<<=(Final& x, const Final& y) {
             x.underlying() <<= y.underlying();
             return x;
         }
     };
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct right_shift_assign : Base {
         friend Final& operator>>=(Final& x, const Final& y) {
             x.underlying() >>= y.underlying();
@@ -139,55 +161,55 @@
     };
     // Unary operators
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct logical_not : Base {
         friend bool operator!(Final const& x) {
             return !(x.underlying());
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct unary_plus : Base {
         friend Final operator+(Final const& x) {
             return x;
         }
     };
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct unary_minus : Base {
         friend Final operator-(Final const& x) {
             return Final(-(x.underlying()));
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct bitwise_not : Base {
         friend Final operator~(Final const& x) {
             return Final(~(x.underlying()));
         }
     };
 
- //~ template <typename Final, typename Base=base_new_type>
+ //~ template <typename Final, typename Base>
     //~ struct address_of : Base {
         //~ Final* operator&() {
             //~ return this;
         //~ }
     //~ };
 
- //~ template <typename Final, typename Derreference=typename reference<Final::underlying_type>::type, typename Base=base_new_type>
+ //~ template <typename Final, typename Derreference=typename reference<Final::underlying_type>::type, typename Base>
     //~ struct derreference : Base {
         //~ Derreference operator*() {
             //~ return *(x.underlying());
         //~ }
     //~ };
 
- //~ template <typename Final, typename Pointer=typename pointer<Final::underlying_type>::type, typename Base=base_new_type>
+ //~ template <typename Final, typename Pointer=typename pointer<Final::underlying_type>::type, typename Base>
     //~ struct member_access : Base {
         //~ Pointer operator->() {
             //~ return x.underlying().operator->();
         //~ }
     //~ };
 
- //~ template <typename Final, class I, class R, typename Base=base_new_type>
+ //~ template <typename Final, class I, class R, typename Base>
     //~ struct subscript : Base {
         //~ R operator[](I n) {
             //~ return x.underlying()[i];
@@ -195,7 +217,7 @@
     //~ };
 
     // Increment and decrement
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct pre_increment : Base {
         friend Final& operator++(Final& x) {
             ++x.underlying();
@@ -203,7 +225,7 @@
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct pre_decrement : Base {
         friend Final& operator--(Final& x) {
             --x.underlying();
@@ -211,20 +233,20 @@
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct post_increment : Base {
         friend Final operator++(Final& x, int) {
             typename Final::underlying_type nrv(x);
- x++;
+ x.underlying()++;
             return nrv;
         }
     };
 
- template <typename Final, typename Base=base_new_type>
+ template <typename Final, typename Base>
     struct post_decrement : Base {
         friend Final operator--(Final& x, int) {
             typename Final::underlying_type nrv(x);
- x--;
+ x.underlying()--;
             return nrv;
         }
     };

Modified: sandbox/opaque/boost/opaque/private_opaque_class.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/private_opaque_class.hpp (original)
+++ sandbox/opaque/boost/opaque/private_opaque_class.hpp 2010-09-28 16:15:32 EDT (Tue, 28 Sep 2010)
@@ -14,7 +14,6 @@
 #define BOOST_OPAQUE_PRIVATE_OPAQUE_CLASS_HPP
 
 #include <boost/opaque/combined_operators.hpp>
-//~ #include <boost/opaque/private_opaque_type.hpp>
 
 #include <boost/type_traits/is_class.hpp>
 #include <boost/type_traits/is_base_of.hpp>

Modified: sandbox/opaque/boost/opaque/public_opaque_class.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/public_opaque_class.hpp (original)
+++ sandbox/opaque/boost/opaque/public_opaque_class.hpp 2010-09-28 16:15:32 EDT (Tue, 28 Sep 2010)
@@ -14,6 +14,7 @@
 #define BOOST_OPAQUE_PUBLIC_OPAQUE_CLASS_HPP
 
 #include <boost/opaque/combined_operators.hpp>
+#include <boost/opaque/transitive_substituable.hpp>
 
 #include <boost/type_traits/is_class.hpp>
 #include <boost/type_traits/is_base_of.hpp>
@@ -38,39 +39,13 @@
         typedef mpl::vector<T> type;
     };
 
- template <typename Final, typename UT, typename Base=base_new_type>
- struct transitive_substituable;
-
- namespace detail {
-
- template <typename Final, typename UT, typename Base, bool B>
- struct transitive_substituable_next_level;
-
- template <typename Final, typename UT, typename Base>
- struct transitive_substituable_next_level<Final, UT, Base, true>
- : transitive_substituable<Final, typename UT::underlying_type, Base> { };
-
- template <typename Final, typename UT, typename Base>
- struct transitive_substituable_next_level<Final, UT, Base, false> : Base { };
-
- }
-
- template <typename Final, typename UT, typename Base>
- struct transitive_substituable
- : detail::transitive_substituable_next_level<Final, UT, Base,
- mpl::and_<is_class<UT>, is_base_of<base_public_opaque_type, UT> >::value>
- {
- operator UT() const {
- return Final::final(this).underlying();
- }
- };
 
 
     template <typename Final, typename T, typename Concepts=boost::mpl::vector0<>, typename Base=base_public_opaque_type>
     class public_opaque_class
         : public
             new_class< Final, T, Concepts,
- transitive_substituable<Final, T,
+ transitive_substituable<base_public_opaque_type>::template type<Final, T,
                     typename inherited_from_undelying<T>::template type<Final, T, Base>
>
>
@@ -78,7 +53,7 @@
     {
         typedef
             new_class< Final, T, Concepts,
- transitive_substituable<Final, T,
+ transitive_substituable<base_public_opaque_type>::template type<Final, T,
                     typename inherited_from_undelying<T>::template type<Final, T, Base>
>
>

Added: sandbox/opaque/boost/opaque/transitive_substituable.hpp
==============================================================================
--- (empty file)
+++ sandbox/opaque/boost/opaque/transitive_substituable.hpp 2010-09-28 16:15:32 EDT (Tue, 28 Sep 2010)
@@ -0,0 +1,54 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_TRANSITIVE_SUBSTITUABLE_HPP
+#define BOOST_OPAQUE_TRANSITIVE_SUBSTITUABLE_HPP
+
+#include <boost/type_traits/is_class.hpp>
+#include <boost/type_traits/is_base_of.hpp>
+#include <boost/mpl/and.hpp>
+
+namespace boost {
+
+ template <typename BaseClass>
+ struct transitive_substituable;
+
+ namespace detail {
+
+ template <typename BaseClass, typename Final, typename UT, typename Base, bool IsConvertible>
+ struct transitive_substituable_next_level;
+
+ template <typename BaseClass, typename Final, typename UT, typename Base>
+ struct transitive_substituable_next_level<BaseClass, Final, UT, Base, true>
+ : transitive_substituable<BaseClass>::template type<Final, typename UT::underlying_type, Base> { };
+
+ template <typename BaseClass, typename Final, typename UT, typename Base>
+ struct transitive_substituable_next_level<BaseClass, Final, UT, Base, false> : Base { };
+
+ }
+
+ template <typename BaseClass>
+ struct transitive_substituable {
+ template <typename Final, typename UT, typename Base>
+ struct type
+ : detail::transitive_substituable_next_level<BaseClass, Final, UT, Base,
+ mpl::and_<is_class<UT>, is_base_of<BaseClass, UT> >::value>
+ {
+ operator UT() const {
+ return Final::final(this).underlying();
+ }
+ };
+ };
+
+}
+
+#endif


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