|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65587 - sandbox/opaque/boost/opaque
From: vicente.botet_at_[hidden]
Date: 2010-09-25 09:26:59
Author: viboes
Date: 2010-09-25 09:26:20 EDT (Sat, 25 Sep 2010)
New Revision: 65587
URL: http://svn.boost.org/trac/boost/changeset/65587
Log:
Opaque: Add transitive_substituable
Text files modified:
sandbox/opaque/boost/opaque/new_type.hpp | 2
sandbox/opaque/boost/opaque/opaque_type.hpp | 36 ++--------
sandbox/opaque/boost/opaque/private_opaque_type.hpp | 9 +-
sandbox/opaque/boost/opaque/public_opaque_type.hpp | 131 ++++++++-------------------------------
4 files changed, 39 insertions(+), 139 deletions(-)
Modified: sandbox/opaque/boost/opaque/new_type.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/new_type.hpp (original)
+++ sandbox/opaque/boost/opaque/new_type.hpp 2010-09-25 09:26:20 EDT (Sat, 25 Sep 2010)
@@ -43,7 +43,7 @@
// Base must inherit from underlying_access<>
// T the underlying type must be regular
- template <typename Final, typename T, typename Base=underlying_access<Final, T, base_new_type> >
+ template <typename Final, typename T, typename Base=underlying_access<Final, T> >
class new_type : public Base
{
public:
Modified: sandbox/opaque/boost/opaque/opaque_type.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/opaque_type.hpp (original)
+++ sandbox/opaque/boost/opaque/opaque_type.hpp 2010-09-25 09:26:20 EDT (Sat, 25 Sep 2010)
@@ -16,44 +16,22 @@
#include <boost/opaque/new_type.hpp>
#include <boost/opaque/combined_operators.hpp>
-namespace boost {
+namespace boost {
template <typename T, typename Final, typename Base>
struct inherited_from_undelying {
- struct type :
- opaque::totally_ordered1< Final
- , opaque::integer_arithmetic1< Final
+ struct type :
+ opaque::totally_ordered1< Final
+ , opaque::integer_arithmetic1< Final
, boost::bitwise1< Final
- , opaque::unit_steppable< Final
+ , opaque::unit_steppable< Final
, underlying_access< Final, T, Base >
>
- >
+ >
>
>
- {};
+ {};
};
-
- template <typename Final, typename T, typename Base>
- class opaque_type : public new_type<Final, T, typename inherited_from_undelying<T, Final, Base>::type >
- {
- public:
- typedef
- new_type<Final, T, typename inherited_from_undelying<T, Final, Base>::type > base_type;
-
- template <typename W>
- explicit opaque_type(W v)
- : base_type(v)
- {
- }
-
- opaque_type() {}
- opaque_type(const opaque_type & rhs) : base_type(rhs.val_) {}
- opaque_type(const Final & rhs) : base_type(rhs.val_){}
- explicit opaque_type(T v) : base_type(v) {}
-
- };
-
-
}
Modified: sandbox/opaque/boost/opaque/private_opaque_type.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/private_opaque_type.hpp (original)
+++ sandbox/opaque/boost/opaque/private_opaque_type.hpp 2010-09-25 09:26:20 EDT (Sat, 25 Sep 2010)
@@ -30,11 +30,10 @@
protected:
typedef private_opaque_type opaque_type_t;
public:
- //~ typedef T underlying_type;
- //~ Can instances of UT be explicitly converted to instances of OT?
- //~ Proposed answer: yes.
- //~ Can instances of UT be implicitly converted to instances of OT?
- //~ Proposed answer: no.
+ //~ Can instances of UT be explicitly converted to instances of OT? Yes
+ //~ Can instances of UT be implicitly converted to instances of OT? No
+ //~ Can instances of OT be explicitly converted to instances of UT? Yes, throogh the underlying function
+ //~ Can instances of OT be implicitly converted to instances of UT? Yes
private_opaque_type() {};
private_opaque_type(const opaque_type_t & rhs) : base_type(rhs.val_) {}
Modified: sandbox/opaque/boost/opaque/public_opaque_type.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/public_opaque_type.hpp (original)
+++ sandbox/opaque/boost/opaque/public_opaque_type.hpp 2010-09-25 09:26:20 EDT (Sat, 25 Sep 2010)
@@ -14,6 +14,7 @@
#define BOOST_OPAQUE_PUBLIC_OPAQUE_TYPE_HPP
#include <boost/opaque/opaque_type.hpp>
+//~ #include <boost/opaque/transitive_substituable.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_base_of.hpp>
@@ -38,144 +39,66 @@
typedef mpl::vector<T> type;
};
- template <typename UT, typename Base>
- struct basic_conv : Base {
- typedef Base base_type;
- basic_conv() {}
- basic_conv(UT val) : base_type(val) {}
- template <typename W>
- explicit basic_conv(W v)
- : base_type(v)
- {}
-
- // public specific conversions
- operator UT () const {
- return this->val_;
- }
- };
+ template <typename UT, typename Base=base_new_type>
+ struct transitive_substituable;
+ namespace detail {
- template <typename T, typename UT, bool B, typename Base>
- struct conv_public_opaque_type2;
-
- template <typename T, typename UT, typename Base>
- struct conv_public_opaque_type2<T, UT,true,Base> : public UT::template conv<T, Base>::type
- {
- typedef typename UT::template conv<T, Base>::type base_type;
- conv_public_opaque_type2() {}
- conv_public_opaque_type2(T val) : base_type(val) {}
- template <typename W>
- explicit conv_public_opaque_type2(W v)
- : base_type(v)
- {}
+ template <typename UT, typename Base, bool B>
+ struct transitive_substituable_next_level;
- };
- template <typename T, typename UT, typename Base>
- struct conv_public_opaque_type2<T, UT, false, Base> : public basic_conv<T, Base>
- {
- typedef basic_conv<T, Base> base_type;
- conv_public_opaque_type2() {}
- conv_public_opaque_type2(T val) : base_type(val) {}
- template <typename W>
- explicit conv_public_opaque_type2(W v)
- : base_type(v)
- {}
+ template <typename UT, typename Base>
+ struct transitive_substituable_next_level<UT, Base, true>
+ : transitive_substituable<typename UT::underlying_type, Base> { };
- };
+ template <typename UT, typename Base>
+ struct transitive_substituable_next_level<UT, Base, false> : Base { };
- template <typename T, typename UT, bool B, typename Base>
- struct conv_public_opaque_type;
+ }
- template <typename T, typename UT, typename Base>
- struct conv_public_opaque_type<T, UT,true,Base> : public UT::template conv<T, Base>::type
- {
- typedef typename UT::template conv<T, Base>::type base_type;
- conv_public_opaque_type() {}
- conv_public_opaque_type(T val) : base_type(val) {}
- template <typename W>
- explicit conv_public_opaque_type(W v)
- : base_type(v)
- {}
-
- // public specific conversions
- operator UT () const {
- return this->val_.operator UT();
- }
- };
- template <typename T, typename UT, typename Base>
- struct conv_public_opaque_type<T, UT, false, Base> : public basic_conv<T, Base>
+ template <typename UT, typename Base>
+ struct transitive_substituable
+ : detail::transitive_substituable_next_level<UT, Base,
+ mpl::and_<is_class<UT>, is_base_of<base_public_opaque_type, UT> >::value>
{
- typedef basic_conv<T, Base> base_type;
- conv_public_opaque_type() {}
- conv_public_opaque_type(T val) : base_type(val) {}
- template <typename W>
- explicit conv_public_opaque_type(W v)
- : base_type(v)
- {}
-
- // public specific conversions
- operator UT () const {
- return this->val_.operator UT();
+ operator UT() const {
+ return this->underlying();
}
};
-
-
template <typename Final, typename T, typename Base=base_public_opaque_type>
class public_opaque_type
: public
- conv_public_opaque_type2<T, T, mpl::and_<is_class<T>, is_base_of<base_public_opaque_type,T> >::value,
- new_type< Final, T, typename inherited_from_undelying<T, Final, Base>::type >
- >
+ new_type< Final, T, transitive_substituable<T, typename inherited_from_undelying<T, Final, Base>::type > >
+
{
typedef
- conv_public_opaque_type2<T, T, mpl::and_<is_class<T>, is_base_of<base_public_opaque_type,T> >::value,
- new_type< Final, T, typename inherited_from_undelying<T, Final, Base>::type >
- > base_type;
+ new_type< Final, T, transitive_substituable<T, typename inherited_from_undelying<T, Final, Base>::type > >
+ base_type;
protected:
typedef public_opaque_type opaque_type_t;
public:
- //~ typedef T underlying_type;
- //~ typedef typename opaque_type< Final, T, Base>::substituables substituables;
- template <typename U, typename B>
- struct conv {
- typedef
- conv_public_opaque_type<U, T,
- mpl::and_<is_class<T>, is_base_of<base_public_opaque_type,T> >::value,
- B> type;
- };
typedef typename get_substituables<T,
mpl::and_<is_class<T>, is_base_of<base_public_opaque_type,T> >::value
>::type substituables;
- //~ Can instances of UT be explicitly converted to instances of OT?
- //~ Proposed answer: yes.
- //~ Can instances of UT be implicitly converted to instances of OT?
- //~ Proposed answer: no.
+ //~ Can instances of UT be explicitly converted to instances of OT? Yes
+ //~ Can instances of UT be implicitly converted to instances of OT? No
+ //~ Can instances of OT be explicitly converted to instances of UT? Yes
+ //~ Can instances of OT be implicitly converted to instances of UT? Yes
public_opaque_type() {}
public_opaque_type(const opaque_type_t & rhs) : base_type(rhs.val_){}
public_opaque_type(const Final & rhs) : base_type(rhs.val_){}
explicit public_opaque_type(T v) : base_type(v) {}
-
template <typename W>
- explicit public_opaque_type(W v)
- : base_type(v)
- {}
+ explicit public_opaque_type(W v) : base_type(v) {}
public_opaque_type & operator=(const opaque_type_t & rhs) {
this->val_ = rhs.val_; return *this;
}
- // public specific conversions
- operator T() const {
- return this->val_;
- }
- operator T() {
- return this->val_;
- }
-
};
}
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