|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65611 - sandbox/opaque/boost/opaque
From: vicente.botet_at_[hidden]
Date: 2010-09-26 15:01:10
Author: viboes
Date: 2010-09-26 15:01:07 EDT (Sun, 26 Sep 2010)
New Revision: 65611
URL: http://svn.boost.org/trac/boost/changeset/65611
Log:
Opaque: Rename _type by _class and add new _type that can be used in a typedef. _class mixins are used in the inhetit part of a class
Added:
sandbox/opaque/boost/opaque/new_class.hpp (contents, props changed)
sandbox/opaque/boost/opaque/private_opaque_class.hpp (contents, props changed)
sandbox/opaque/boost/opaque/public_opaque_class.hpp (contents, props changed)
Text files modified:
sandbox/opaque/boost/opaque/combined_operators.hpp | 38 +++++++++++++++++++++++++++-----
sandbox/opaque/boost/opaque/macros.hpp | 30 ++++++++++++++++++++-----
sandbox/opaque/boost/opaque/new_type.hpp | 47 +++++++++++++++++++++++++++++----------
sandbox/opaque/boost/opaque/opaque.hpp | 3 ++
sandbox/opaque/boost/opaque/opaque_type.hpp | 18 ---------------
sandbox/opaque/boost/opaque/private_opaque_type.hpp | 20 +++++++++-------
sandbox/opaque/boost/opaque/public_opaque_type.hpp | 20 +++++++++-------
7 files changed, 116 insertions(+), 60 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-26 15:01:07 EDT (Sun, 26 Sep 2010)
@@ -24,6 +24,11 @@
template <typename Final, typename Base=base_new_type>
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>
+ 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> > {};
@@ -67,10 +72,11 @@
struct partially_ordered1 : boost::less_than_comparable1<Final, ope::less_than<Final, Base> > {};
- template <class T, class B = base_new_type >
+ template <class T, class UT, class B = base_new_type >
struct totally_ordered1
: opaque::less_than_comparable1<T
- , opaque::equality_comparable1<T, B
+ //~ , opaque::equality_comparable1<T, B
+ , opaque::using_equality_comparable1::template type<T, UT, B
> > {};
//~ template <class T, class U, class B = base_new_type >
@@ -184,10 +190,10 @@
//~ , opaque::totally_ordered2<T, U, B
//~ > > {};
- template <class T, class B = base_new_type >
+ template <class T, class UT, class B = base_new_type >
struct ordered_ring_operators1
: opaque::ring_operators1<T
- , opaque::totally_ordered1<T, B
+ , opaque::totally_ordered1<T, UT, B
> > {};
//~ template <class T, class U, class B = base_new_type >
@@ -209,14 +215,34 @@
//~ , opaque::totally_ordered2<T, U, B
//~ > > {};
- template <class T, class B = base_new_type >
+ template <class T, class UT, class B = base_new_type >
struct ordered_field_operators1
: opaque::field_operators1<T
- , opaque::totally_ordered1<T, B
+ , opaque::totally_ordered1<T, UT, B
> > {};
+
}
+ template <typename T>
+ struct inherited_from_undelying {
+ template <typename Final, typename UT, typename Base=base_new_type>
+ struct type :
+ opaque::totally_ordered1< Final, T
+ , opaque::integer_arithmetic1< Final
+ , boost::bitwise1< Final
+ , opaque::unit_steppable< Final
+ , opaque::ope::unary_plus< Final
+ , opaque::ope::unary_minus< Final
+ , Base
+ >
+ >
+ >
+ >
+ >
+ >
+ {};
+ };
}
Modified: sandbox/opaque/boost/opaque/macros.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/macros.hpp (original)
+++ sandbox/opaque/boost/opaque/macros.hpp 2010-09-26 15:01:07 EDT (Sun, 26 Sep 2010)
@@ -13,27 +13,37 @@
#ifndef BOOST_OPAQUE_MACROS_HPP
#define BOOST_OPAQUE_MACROS_HPP
+#include <boost/config.hpp>
#include <boost/opaque/private_opaque_type.hpp>
#include <boost/opaque/public_opaque_type.hpp>
+#include <boost/opaque/private_opaque_class.hpp>
+#include <boost/opaque/public_opaque_class.hpp>
#define BOOST_OPAQUE_PUBLIC_FORWARD_CONSTRUCTORS(UT, OT) \
OT(){} \
template <typename W> \
explicit OT(W w) \
- : boost::public_opaque_type<OT, UT>(w) \
+ : boost::public_opaque_class<OT, UT>(w) \
{}\
OT(OT const& r) \
- : boost::public_opaque_type<OT, UT>(r) \
+ : boost::public_opaque_class<OT, UT>(r) \
{}
#define BOOST_OPAQUE_PUBLIC_OPERATIONS(UT, OT) \
BOOST_OPAQUE_PUBLIC_FORWARD_CONSTRUCTORS(UT,OT)\
+
+#if 1
#define BOOST_OPAQUE_PUBLIC_TYPEDEF(UT, OT) \
-struct OT: boost::public_opaque_type<OT, UT> \
+struct OT: boost::public_opaque_class<OT, UT> \
{\
BOOST_OPAQUE_PUBLIC_OPERATIONS(UT,OT);\
}
+#else
+#define BOOST_OPAQUE_PUBLIC_TYPEDEF(UT, OT) \
+struct BOOST_JOIN(OT, _tag) {};\
+typedef boost::public_opaque_type<UT, BOOST_JOIN(OT, _tag)> OT
+#endif
//~ template <typename T> explicit OT(T v) : boost::private_opaque_type<OT, UT>(v) {}
@@ -42,10 +52,10 @@
OT(){}\
template <typename W> \
explicit OT(W w) \
- : boost::private_opaque_type<OT, UT>(w) \
+ : boost::private_opaque_class<OT, UT>(w) \
{}\
OT(OT const& r) \
- : boost::private_opaque_type<OT, UT>(r) \
+ : boost::private_opaque_class<OT, UT>(r) \
{}
#define BOOST_OPAQUE_PRIVATE_OPERATIONS(UT, OT) \
@@ -53,10 +63,18 @@
+
+#if 1
#define BOOST_OPAQUE_PRIVATE_TYPEDEF(UT, OT) \
-struct OT: boost::private_opaque_type<OT, UT> \
+struct OT: boost::private_opaque_class<OT, UT> \
{\
BOOST_OPAQUE_PRIVATE_OPERATIONS(UT,OT);\
}
+#else
+#define BOOST_OPAQUE_PRIVATE_TYPEDEF(UT, OT) \
+struct BOOST_JOIN(OT, _tag) {};\
+typedef boost::private_opaque_type<UT, BOOST_JOIN(OT, _tag)> OT
+#endif
+
#endif
Added: sandbox/opaque/boost/opaque/new_class.hpp
==============================================================================
--- (empty file)
+++ sandbox/opaque/boost/opaque/new_class.hpp 2010-09-26 15:01:07 EDT (Sun, 26 Sep 2010)
@@ -0,0 +1,75 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_NEW_CLASS_HPP
+#define BOOST_OPAQUE_NEW_CLASS_HPP
+
+#include <boost/opaque/new_type.hpp>
+
+namespace boost {
+
+ template <typename Final, typename T, typename Base=base_new_type >
+ class new_class : public Base
+ {
+ public:
+ typedef T underlying_type;
+
+ template <typename W>
+ explicit new_class(W v) : val_(v) {}
+ new_class(){}
+ new_class(const new_class & rhs) : val_(rhs.val_) {}
+ explicit new_class(T v) : val_(v) {}
+ protected:
+ T val_;
+ new_class & operator=(const new_class & rhs) {
+ val_ = rhs.val_; return *this;
+ }
+
+ public:
+ underlying_type const& underlying() const {
+ return val_;
+ }
+ underlying_type& underlying() {
+ return val_;
+ }
+
+ template<typename F>
+ static underlying_type& underlying(F* f){
+ return final(f).underlying();
+ }
+
+ template<typename F>
+ static underlying_type const& underlying(F const* f){
+ return final(f).underlying();
+ }
+
+ template<typename F>
+ static Final const& final(F const* f) {
+ return static_cast<Final const&>(*f);
+ }
+ template<typename F>
+ Final& final(F* f) {
+ return static_cast<Final&>(*f);
+ }
+
+ };
+
+ template <typename T, typename Final, typename UT, typename Base >
+ T opaque_static_cast(new_class<Final, UT, Base> const& v)
+ {
+ return static_cast<T>(v.underlying());
+ }
+
+}
+
+
+#endif
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-26 15:01:07 EDT (Sun, 26 Sep 2010)
@@ -13,15 +13,38 @@
#ifndef BOOST_OPAQUE_NEW_TYPE_HPP
#define BOOST_OPAQUE_NEW_TYPE_HPP
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/fold.hpp>
+
namespace boost {
class base_new_type {};
+ ////// implementation //////
+ namespace detail{
+
+ template<typename NT, typename UT, typename State, typename Concept>
+ struct do_inhetit : Concept::template type<NT, UT, State> {
+ };
+
+ template<typename NT, typename UT>
+ struct inherit {
+ template<typename State, typename Concept>
+ struct apply{
+ typedef do_inhetit<NT, UT, State, Concept> type;
+ };
+ };
- // T the underlying type must be regular
- template <typename Final, typename T, typename Base=base_new_type >
- class new_type : public Base
+ }
+ template <typename T, typename Tag, typename Concepts=boost::mpl::vector0<>, typename Base=base_new_type>
+ class new_type
+ : public
+ boost::mpl::fold<Concepts, Base, detail::inherit<new_type<T, Tag, Concepts, Base>, T> >::type
{
+ typedef typename
+ boost::mpl::fold<Concepts, Base, detail::inherit<new_type<T, Tag, Concepts, Base>, T> >::type
+ base_type;
+
public:
typedef T underlying_type;
@@ -30,11 +53,11 @@
new_type(){}
new_type(const new_type & rhs) : val_(rhs.val_) {}
explicit new_type(T v) : val_(v) {}
+ //~ new_type & operator=(const new_type & rhs) {
+ //~ val_ = rhs.val_; return *this;
+ //~ }
protected:
T val_;
- new_type & operator=(const new_type & rhs) {
- val_ = rhs.val_; return *this;
- }
public:
underlying_type const& underlying() const {
@@ -55,18 +78,18 @@
}
template<typename F>
- static Final const& final(F const* f) {
- return static_cast<Final const&>(*f);
+ static new_type const& final(F const* f) {
+ return static_cast<new_type const&>(*f);
}
template<typename F>
- Final& final(F* f) {
- return static_cast<Final&>(*f);
+ new_type& final(F* f) {
+ return static_cast<new_type&>(*f);
}
};
- template <typename T, typename Final, typename UT, typename Base >
- T opaque_static_cast(new_type<Final, UT, Base> const& v)
+ template <typename T, typename UT, typename Base, typename Tag >
+ T opaque_static_cast(new_type<UT, Base,Tag> const& v)
{
return static_cast<T>(v.underlying());
}
Modified: sandbox/opaque/boost/opaque/opaque.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/opaque.hpp (original)
+++ sandbox/opaque/boost/opaque/opaque.hpp 2010-09-26 15:01:07 EDT (Sun, 26 Sep 2010)
@@ -14,10 +14,13 @@
#define BOOST_OPAQUE_OPAQUE_HPP
#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>
+#include <boost/opaque/public_opaque_class.hpp>
#include <boost/opaque/macros.hpp>
#include <boost/mpl/bool.hpp>
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-26 15:01:07 EDT (Sun, 26 Sep 2010)
@@ -18,24 +18,6 @@
namespace boost {
- template <typename T, typename Final, typename Base>
- struct inherited_from_undelying {
- struct type :
- opaque::totally_ordered1< Final
- , opaque::integer_arithmetic1< Final
- , boost::bitwise1< Final
- , opaque::unit_steppable< Final
- , opaque::ope::unary_plus< Final
- , opaque::ope::unary_minus< Final
- , Base
- >
- >
- >
- >
- >
- >
- {};
- };
}
Added: sandbox/opaque/boost/opaque/private_opaque_class.hpp
==============================================================================
--- (empty file)
+++ sandbox/opaque/boost/opaque/private_opaque_class.hpp 2010-09-26 15:01:07 EDT (Sun, 26 Sep 2010)
@@ -0,0 +1,63 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_PRIVATE_OPAQUE_CLASS_HPP
+#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>
+#include <boost/mpl/and.hpp>
+
+namespace boost {
+
+
+ template <typename Final, typename T, typename Base=base_private_opaque_type>
+ class private_opaque_class : public
+ new_class< Final, T,
+ transitive_explicit_substituable<Final, T,
+ typename inherited_from_undelying<T>::template type<Final, T, Base>
+ >
+ >
+ {
+ typedef
+ new_class< Final, T,
+ transitive_explicit_substituable<Final, T,
+ typename inherited_from_undelying<T>::template type<Final, T, Base>
+ >
+ >
+ base_type;
+ protected:
+ typedef private_opaque_class opaque_class_t;
+ public:
+ //~ 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.
+ //~ Waiting for explicit conversion operators,, the explicit conversion must be done through the underlying function
+ //~ Can instances of OT be implicitly converted to instances of UT? No
+
+ private_opaque_class() {};
+ private_opaque_class(const opaque_class_t & rhs) : base_type(rhs.val_) {}
+ private_opaque_class(const Final & rhs) : base_type(rhs.val_) {}
+ explicit private_opaque_class(T v) : base_type(v) {};
+ template <typename W>
+ explicit private_opaque_class(W v)
+ : base_type(v)
+ {}
+ };
+
+}
+
+
+#endif
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-26 15:01:07 EDT (Sun, 26 Sep 2010)
@@ -13,7 +13,8 @@
#ifndef BOOST_OPAQUE_PRIVATE_OPAQUE_TYPE_HPP
#define BOOST_OPAQUE_PRIVATE_OPAQUE_TYPE_HPP
-#include <boost/opaque/opaque_type.hpp>
+#include <boost/opaque/combined_operators.hpp>
+#include <boost/opaque/new_class.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_base_of.hpp>
@@ -54,18 +55,20 @@
};
#endif
- template <typename Final, typename T, typename Base=base_private_opaque_type>
+ template <typename T, typename Base=base_private_opaque_type, typename Tag=void>
class private_opaque_type : public
- new_type< Final, T,
- transitive_explicit_substituable<Final, T,
- typename inherited_from_undelying<T, Final, Base>::type
+ new_class< private_opaque_type<T,Base,Tag >, T,
+ transitive_explicit_substituable<private_opaque_type<T,Base,Tag >, T,
+ //~ typename inherited_from_undelying<T, private_opaque_type<T,Base,Tag>, Base>::type
+ typename inherited_from_undelying<T>::template type<private_opaque_type<T,Base,Tag>, T, Base>
>
>
{
typedef
- new_type< Final, T,
- transitive_explicit_substituable<Final, T,
- typename inherited_from_undelying<T, Final, Base>::type
+ new_class< private_opaque_type<T,Base,Tag >, T,
+ transitive_explicit_substituable<private_opaque_type<T,Base,Tag >, T,
+ //~ typename inherited_from_undelying<T, private_opaque_type<T,Base,Tag >, Base>::type
+ typename inherited_from_undelying<T>::template type<private_opaque_type<T,Base,Tag>, T, Base>
>
>
base_type;
@@ -80,7 +83,6 @@
private_opaque_type() {};
private_opaque_type(const opaque_type_t & rhs) : base_type(rhs.val_) {}
- private_opaque_type(const Final & rhs) : base_type(rhs.val_) {}
explicit private_opaque_type(T v) : base_type(v) {};
template <typename W>
explicit private_opaque_type(W v)
Added: sandbox/opaque/boost/opaque/public_opaque_class.hpp
==============================================================================
--- (empty file)
+++ sandbox/opaque/boost/opaque/public_opaque_class.hpp 2010-09-26 15:01:07 EDT (Sun, 26 Sep 2010)
@@ -0,0 +1,70 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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_PUBLIC_OPAQUE_CLASS_HPP
+#define BOOST_OPAQUE_PUBLIC_OPAQUE_CLASS_HPP
+
+#include <boost/opaque/combined_operators.hpp>
+#include <boost/opaque/public_opaque_type.hpp>
+
+#include <boost/type_traits/is_class.hpp>
+#include <boost/type_traits/is_base_of.hpp>
+#include <boost/mpl/push_front.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/vector.hpp>
+
+namespace boost {
+
+
+ template <typename Final, typename T, typename Base=base_public_opaque_type>
+ class public_opaque_class
+ : public
+ new_class< Final, T,
+ transitive_substituable<Final, T,
+ typename inherited_from_undelying<T>::template type<Final, T, Base>
+ >
+ >
+
+ {
+ typedef
+ new_class< Final, T,
+ transitive_substituable<Final, T,
+ typename inherited_from_undelying<T>::template type<Final, T, Base>
+ >
+ >
+ base_type;
+
+ protected:
+ typedef public_opaque_class opaque_class_t;
+ public:
+ 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? 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_class() {}
+ public_opaque_class(const opaque_class_t & rhs) : base_type(rhs.val_){}
+ public_opaque_class(const Final & rhs) : base_type(rhs.val_){}
+ explicit public_opaque_class(T v) : base_type(v) {}
+ template <typename W>
+ explicit public_opaque_class(W v) : base_type(v) {}
+
+ };
+
+}
+
+
+#endif
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-26 15:01:07 EDT (Sun, 26 Sep 2010)
@@ -13,7 +13,8 @@
#ifndef BOOST_OPAQUE_PUBLIC_OPAQUE_TYPE_HPP
#define BOOST_OPAQUE_PUBLIC_OPAQUE_TYPE_HPP
-#include <boost/opaque/opaque_type.hpp>
+#include <boost/opaque/combined_operators.hpp>
+#include <boost/opaque/new_class.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_base_of.hpp>
@@ -65,20 +66,22 @@
}
};
- template <typename Final, typename T, typename Base=base_public_opaque_type>
+ template <typename T, typename Base=base_public_opaque_type, typename Tag=void>
class public_opaque_type
: public
- new_type< Final, T,
- transitive_substituable<Final, T,
- typename inherited_from_undelying<T, Final, Base>::type
+ new_class< public_opaque_type<T,Base,Tag >, T,
+ transitive_substituable<public_opaque_type<T,Base,Tag >, T,
+ //~ typename inherited_from_undelying<T, public_opaque_type<T,Base,Tag >, Base>::type
+ typename inherited_from_undelying<T>::template type<public_opaque_type<T,Base,Tag>, T, Base>
>
>
{
typedef
- new_type< Final, T,
- transitive_substituable<Final, T,
- typename inherited_from_undelying<T, Final, Base>::type
+ new_class< public_opaque_type<T,Base,Tag >, T,
+ transitive_substituable<public_opaque_type<T,Base,Tag >, T,
+ //~ typename inherited_from_undelying<T, public_opaque_type<T,Base,Tag >, Base>::type
+ typename inherited_from_undelying<T>::template type<public_opaque_type<T,Base,Tag>, T, Base>
>
>
base_type;
@@ -97,7 +100,6 @@
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) {}
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