|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r70626 - in sandbox/opaque/boost/opaque: . meta_mixin
From: vicente.botet_at_[hidden]
Date: 2011-03-27 09:22:04
Author: viboes
Date: 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
New Revision: 70626
URL: http://svn.boost.org/trac/boost/changeset/70626
Log:
Opaque: Update comments + some renamings
Text files modified:
sandbox/opaque/boost/opaque/boolean.hpp | 7 +
sandbox/opaque/boost/opaque/macros.hpp | 251 +++++++++++++++++++++++++++++++++++++--
sandbox/opaque/boost/opaque/meta_mixin/combined_operators.hpp | 42 +++---
sandbox/opaque/boost/opaque/meta_mixin/inherited_from_underlying.hpp | 82 ++++++++++--
sandbox/opaque/boost/opaque/meta_mixin/linear_hierarchy.hpp | 10 +
sandbox/opaque/boost/opaque/meta_mixin/operators.hpp | 67 ++++++++++
sandbox/opaque/boost/opaque/meta_mixin/transitive_explicit_substituable.hpp | 76 ++++++-----
sandbox/opaque/boost/opaque/meta_mixin/transitive_substituable.hpp | 59 ++++----
sandbox/opaque/boost/opaque/new_class.hpp | 192 ++++++++++++++++++++++-------
sandbox/opaque/boost/opaque/new_class_macro.hpp | 21 +++
sandbox/opaque/boost/opaque/new_type.hpp | 80 ++++++++----
sandbox/opaque/boost/opaque/new_type_macro.hpp | 19 +++
sandbox/opaque/boost/opaque/private_opaque_class.hpp | 117 +++++++++++-------
sandbox/opaque/boost/opaque/private_opaque_type.hpp | 67 ++++++----
sandbox/opaque/boost/opaque/public_opaque_class.hpp | 131 +++++++++----------
sandbox/opaque/boost/opaque/public_opaque_type.hpp | 65 ++++++---
16 files changed, 918 insertions(+), 368 deletions(-)
Modified: sandbox/opaque/boost/opaque/boolean.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/boolean.hpp (original)
+++ sandbox/opaque/boost/opaque/boolean.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -10,6 +10,10 @@
//
//////////////////////////////////////////////////////////////////////////////
+/**
+ * @File Defines an opaque boolean class.
+ */
+
#ifndef BOOST_OPAQUE_BOOLEAN_HPP
#define BOOST_OPAQUE_BOOLEAN_HPP
@@ -25,12 +29,15 @@
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_);
}
Modified: sandbox/opaque/boost/opaque/macros.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/macros.hpp (original)
+++ sandbox/opaque/boost/opaque/macros.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -10,6 +10,11 @@
//
//////////////////////////////////////////////////////////////////////////////
+/**
+ * @file
+ * Defines helper macros.
+ */
+
#ifndef BOOST_OPAQUE_MACROS_HPP
#define BOOST_OPAQUE_MACROS_HPP
@@ -20,6 +25,27 @@
#include <boost/opaque/private_opaque_class.hpp>
#include <boost/opaque/public_opaque_class.hpp>
+
+/** forward the constructors from the new class @c OT to the base class @ BASE
+
+ @Note This macro can be used only inside the public part of a class.
+
+ @Params
+ @Param{OT, the class been defined}
+ @Param{BASE, the base class}
+
+ @Result
+ @code
+ OT(){}
+ template <typename W>
+ explicit OT(W w)
+ : BASE(w)
+ {}
+ OT(OT const& r)
+ : BASE(r.val_)
+ {}
+ @endcode
+ */
#define BOOST_OPAQUE_FORWARD_CONSTRUCTORS(OT,BASE) \
OT(){} \
template <typename W> \
@@ -30,33 +56,143 @@
: BASE(r.val_) \
{}
-#define BOOST_OPAQUE_PUBLIC_FORWARD_CONSTRUCTORS(UT, OT) \
- BOOST_OPAQUE_FORWARD_CONSTRUCTORS(OT,(boost::opaque::public_opaque_class<OT, UT>))
-#define BOOST_OPAQUE_PUBLIC_OPERATIONS(UT, OT) \
- BOOST_OPAQUE_PUBLIC_FORWARD_CONSTRUCTORS(UT,OT)\
+/**
+ Specialize inherited_from_underlying for the type @ OT just inheriting the ones from its underlying type.
+
+ @Note This macro can be used only outside a namespace.
+
+ @Params
+ @Param{OT, the opaque type}
+
+ @Result
+ @code
+ namespace boost {
+ namespace opaque {
+ template <typename Bool>
+ struct inherited_from_underlying<OT,Bool>
+ : inherited_from_underlying<typename OT::underlying_type,Bool> { };
+ }
+ }
+ @endcode
+ */
+#define BOOST_OPAQUE_INHERIT_FROM_UNDERLYING(OT) \
+namespace boost {\
+namespace opaque {\
+ template <typename Bool>\
+ struct inherited_from_underlying<OT,Bool>\
+ : inherited_from_underlying<typename OT::underlying_type,Bool> { };\
+} \
+}
+
+#if !defined(BOOST_OPAQUE_DOXYGEN_INVOKED)
-//////////////////////////
#define BOOST_OPAQUE_EXT_PUBLIC_TYPEDEF(UT, OT, B) \
-struct BOOST_JOIN(OT, _tag) {};\
-typedef boost::opaque::public_opaque_type<UT, BOOST_JOIN(OT, _tag), B> OT
+ struct BOOST_JOIN(OT, _tag) {};\
+ typedef boost::opaque::public_opaque_type<UT, BOOST_JOIN(OT, _tag), B> OT
+
+#endif
+/**
+ Declares a @c public_opaque_type typedef @c OT defining a specific tag @c OT_tag having @c boost::opaque::boolean as <em>Boolean</em> type.
+
+ @Note This macro must be used inside the @c OT's namespace.
+ @Params
+ @Param{UT, the underlying type}
+ @Param{OT, the opaque type}
+
+ @Result
+ @code
+ struct OT_tag {};
+ typedef boost::opaque::public_opaque_type<UT, OT_tag, boost::opaque::boolean> OT
+ @endcode
+ */
#define BOOST_OPAQUE_BOOLEAN_PUBLIC_TYPEDEF(UT, OT) \
BOOST_OPAQUE_EXT_PUBLIC_TYPEDEF(UT, OT, boost::opaque::boolean)
+/**
+ Declares a @c public_opaque_type typedef @c OT defining a specific tag @c OT_tag having @c bool as <em>Boolean</em> type.
+
+ @Note This macro must be used inside the @c OT's namespace.
+
+ @Params
+ @Param{UT, the underlying type}
+ @Param{OT, the opaque type}
+
+ @Result
+ @code
+ struct OT_tag {};
+ typedef boost::opaque::public_opaque_type<UT, OT_tag, bool> OT
+ @endcode
+ */
#define BOOST_OPAQUE_PUBLIC_TYPEDEF(UT, OT) \
BOOST_OPAQUE_EXT_PUBLIC_TYPEDEF(UT, OT, bool)
//////////////////////////
+#if !defined(BOOST_OPAQUE_DOXYGEN_INVOKED)
+
#define BOOST_OPAQUE_EXT_PUBLIC_CLASS(UT, NT1, B) \
-struct NT1 : boost::opaque::public_opaque_class<NT1, UT,B> \
-{ \
+ struct NT1 : boost::opaque::public_opaque_class<NT1, UT,B> \
+ { \
BOOST_OPAQUE_FORWARD_CONSTRUCTORS(NT1, (boost::opaque::public_opaque_class<NT1, UT,B>)) \
-}
+ }
+#endif
+
+/**
+ Declares a @c public_opaque_class @c OT having @c boost::opaque::boolean as <em>Boolean</em> type.
+
+ @Note This macro must be used inside the OT's namespace.
+
+ @Params
+ @Param{UT, the underlying type}
+ @Param{OT, the opaque type}
+
+ @Result
+ @code
+ struct NT1 : boost::opaque::public_opaque_class<NT1, UT,boost::opaque::boolean>
+ {
+ typedef boost::opaque::public_opaque_class<NT1, UT,boost::opaque::boolean> base_type;
+ OT(){}
+ template <typename W>
+ explicit OT(W w)
+ : base_type(w)
+ {}
+ OT(OT const& r)
+ : base_type(r.val_)
+ {}
+ }
+ @endcode
+ */
#define BOOST_OPAQUE_BOOLEAN_PUBLIC_CLASS(UT, OT) \
BOOST_OPAQUE_EXT_PUBLIC_CLASS(UT, OT, boost::opaque::boolean)
+
+/**
+ Declares a @c public_opaque_class @c OT having @c bool as <em>Boolean</em> type.
+
+ @Note This macro must be used inside the OT's namespace.
+
+ @Params
+ @Param{UT, the underlying type}
+ @Param{OT, the opaque type}
+
+ @Result
+ @code
+ struct NT1 : boost::opaque::public_opaque_class<NT1, UT, bool>
+ {
+ typedef boost::opaque::public_opaque_class<NT1, UT,bool> base_type;
+ OT(){}
+ template <typename W>
+ explicit OT(W w)
+ : base_type(w)
+ {}
+ OT(OT const& r)
+ : base_type(r.val_)
+ {}
+ }
+ @endcode
+ */
#define BOOST_OPAQUE_PUBLIC_CLASS(UT, OT) \
BOOST_OPAQUE_EXT_PUBLIC_CLASS(UT, OT, bool)
@@ -68,26 +204,115 @@
BOOST_OPAQUE_PRIVATE_FORWARD_CONSTRUCTORS(UT, OT)
//////////////////////////
+#if !defined(BOOST_OPAQUE_DOXYGEN_INVOKED)
+
#define BOOST_OPAQUE_EXT_PRIVATE_TYPEDEF(UT, OT,B) \
-struct BOOST_JOIN(OT, _tag) {};\
-typedef boost::opaque::private_opaque_type<UT, BOOST_JOIN(OT, _tag),B> OT
+ struct BOOST_JOIN(OT, _tag) {};\
+ typedef boost::opaque::private_opaque_type<UT, BOOST_JOIN(OT, _tag),B> OT
+#endif
+
+/**
+ Declares a @c private_opaque_type typedef @c OT defining a specific tag @c OT_tag having @c bool as <em>Boolean</em> type.
+
+ @Note This macro must be used inside the OT's namespace.
+
+ @Params
+ @Param{UT, the underlying type}
+ @Param{OT, the opaque type}
+
+ @Result
+ @code
+ struct OT_tag {};
+ typedef boost::opaque::private_opaque_type<UT, OT_tag, boost::opaque::boolean> OT
+ @endcode
+ */
#define BOOST_OPAQUE_BOOLEAN_PRIVATE_TYPEDEF(UT, OT) \
BOOST_OPAQUE_EXT_PRIVATE_TYPEDEF(UT, OT, boost::opaque::boolean)
+/**
+ Declares a @c private_opaque_type typedef @c OT defining a specific tag @c OT_tag having @c bool as <em>Boolean</em> type.
+
+ @Note This macro must be used inside the OT's namespace.
+
+ @Params
+ @Param{UT, the underlying type}
+ @Param{OT, the opaque type}
+
+ @Result
+ @code
+ struct OT_tag {};
+ typedef boost::opaque::private_opaque_type<UT, OT_tag, bool> OT
+ @endcode
+ */
#define BOOST_OPAQUE_PRIVATE_TYPEDEF(UT, OT) \
BOOST_OPAQUE_EXT_PRIVATE_TYPEDEF(UT, OT, bool)
-//////////////////////////
+#if !defined(BOOST_OPAQUE_DOXYGEN_INVOKED)
+
#define BOOST_OPAQUE_EXT_PRIVATE_CLASS(UT, NT1, B) \
struct NT1 : boost::opaque::private_opaque_class<NT1, UT,B> \
{ \
+ typedef boost::opaque::private_opaque_class<NT1, UT, B> base_type; \
BOOST_OPAQUE_FORWARD_CONSTRUCTORS(NT1, (boost::opaque::private_opaque_class<NT1, UT,B>)) \
}
+#endif
+
+/**
+ Declares a @c private_opaque_class @c OT having @c boost::opaque::boolean as <em>Boolean</em> type.
+
+ @Note This macro must be used inside the OT's namespace.
+
+ @Params
+ @Param{UT, the underlying type}
+ @Param{OT, the opaque type}
+
+ @Result
+ @code
+ struct NT1 : boost::opaque::private_opaque_class<NT1, UT, boost::opaque::boolean>
+ {
+ typedef boost::opaque::private_opaque_class<NT1, UT,boost::opaque::boolean> base_type;
+ OT(){}
+ template <typename W>
+ explicit OT(W w)
+ : base_type(w)
+ {}
+ OT(OT const& r)
+ : base_type(r.val_)
+ {}
+ }
+ @endcode
+ */
+
#define BOOST_OPAQUE_BOOLEAN_PRIVATE_CLASS(UT, OT) \
BOOST_OPAQUE_EXT_PRIVATE_CLASS(UT, OT, boost::opaque::boolean)
+/**
+ Declares a @c private_opaque_class @c OT having @c bool as <em>Boolean</em> type.
+
+ @Note This macro must be used inside the OT's namespace.
+
+ @Params
+ @Param{UT, the underlying type}
+ @Param{OT, the opaque type}
+
+ @Result
+ @code
+ struct NT1 : boost::opaque::private_opaque_class<NT1, UT, bool>
+ {
+ typedef boost::opaque::private_opaque_class<NT1, UT,bool> base_type;
+ OT(){}
+ template <typename W>
+ explicit OT(W w)
+ : base_type(w)
+ {}
+ OT(OT const& r)
+ : base_type(r.val_)
+ {}
+ }
+ @endcode
+ */
#define BOOST_OPAQUE_PRIVATE_CLASS(UT, OT) \
BOOST_OPAQUE_EXT_PRIVATE_CLASS(UT, OT, bool)
Modified: sandbox/opaque/boost/opaque/meta_mixin/combined_operators.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/meta_mixin/combined_operators.hpp (original)
+++ sandbox/opaque/boost/opaque/meta_mixin/combined_operators.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -242,7 +242,7 @@
//////////////////////////////////////////////////////////////////////////////
- //~ template <class T, class U, typename Base = base_new_type >
+ //~ template <class T, class U, typename Base = base_opaque_type >
//~ struct additive2
//~ : opaque::addable2<T, U
//~ , opaque::subtractable2<T, U, Base
@@ -263,7 +263,7 @@
//////////////////////////////////////////////////////////////////////////////
- //~ template <class T, class U, typename Base = base_new_type >
+ //~ template <class T, class U, typename Base = base_opaque_type >
//~ struct multiplicative2
//~ : opaque::multipliable2<T, U
//~ , opaque::dividable2<T, U, Base
@@ -284,7 +284,7 @@
//////////////////////////////////////////////////////////////////////////////
- //~ template <class T, class U, typename Base = base_new_type >
+ //~ template <class T, class U, typename Base = base_opaque_type >
//~ struct integer_multiplicative2
//~ : opaque::multiplicative2<T, U
//~ , opaque::modable2<T, U, Base
@@ -298,7 +298,7 @@
struct integer_multiplicative1
{
- template <typename Final, typename Base = base_new_type >
+ template <typename Final, typename Base = base_opaque_type >
struct type : Base
{
BOOST_OPAQUE_INTEGER_MULTIPLICATIVE1(Final)
@@ -307,7 +307,7 @@
//////////////////////////////////////////////////////////////////////////////
- //~ template <class T, class U, typename Base = base_new_type >
+ //~ template <class T, class U, typename Base = base_opaque_type >
//~ struct arithmetic2
//~ : opaque::additive2<T, U
//~ , opaque::multiplicative2<T, U, Base
@@ -321,7 +321,7 @@
struct using_arithmetic1
{
- template <typename Final, typename Base = base_new_type >
+ template <typename Final, typename Base = base_opaque_type >
struct type : Base
{
BOOST_OPAQUE_ARITHMETIC1(Final)
@@ -330,7 +330,7 @@
//////////////////////////////////////////////////////////////////////////////
- //~ template <class T, class U, typename Base = base_new_type >
+ //~ template <class T, class U, typename Base = base_opaque_type >
//~ struct integer_arithmetic2
//~ : additive2<T, U
//~ , integer_multiplicative2<T, U, Base
@@ -344,7 +344,7 @@
struct using_integer_arithmetic1
{
- template <typename Final, typename Base = base_new_type >
+ template <typename Final, typename Base = base_opaque_type >
struct type : Base
{
BOOST_OPAQUE_INTEGER_ARITHMETIC1(Final)
@@ -353,7 +353,7 @@
//////////////////////////////////////////////////////////////////////////////
- //~ template <class T, class U, typename Base = base_new_type >
+ //~ template <class T, class U, typename Base = base_opaque_type >
//~ struct bitwise2
//~ : opaque::xorable2<T, U
//~ , opaque::andable2<T, U
@@ -369,7 +369,7 @@
struct using_bitwise1
{
- template <typename Final, typename Base = base_new_type >
+ template <typename Final, typename Base = base_opaque_type >
struct type : Base
{
BOOST_OPAQUE_BITWISE1(Final)
@@ -384,7 +384,7 @@
struct using_unit_steppable
{
- template <typename Final, typename Base = base_new_type >
+ template <typename Final, typename Base = base_opaque_type >
struct type : Base
{
BOOST_OPAQUE_UNIT_STEPABLE(Final)
@@ -393,7 +393,7 @@
//////////////////////////////////////////////////////////////////////////////
- //~ template <class T, class U, typename Base = base_new_type >
+ //~ template <class T, class U, typename Base = base_opaque_type >
//~ struct shiftable2
//~ : opaque::left_shiftable2<T, U
//~ , opaque::right_shiftable2<T, U, Base
@@ -407,7 +407,7 @@
struct using_shiftable1
{
- template <typename Final, typename Base = base_new_type >
+ template <typename Final, typename Base = base_opaque_type >
struct type : Base
{
BOOST_OPAQUE_SHIFTABLE1(Final)
@@ -416,7 +416,7 @@
//////////////////////////////////////////////////////////////////////////////
- //~ template <class T, class U, typename Base = base_new_type >
+ //~ template <class T, class U, typename Base = base_opaque_type >
//~ struct ring_operators2
//~ : opaque::additive2<T, U
//~ , opaque::subtractable2_left<T, U
@@ -431,7 +431,7 @@
struct using_ring_operators1
{
- template <typename Final, typename Base = base_new_type >
+ template <typename Final, typename Base = base_opaque_type >
struct type: Base
{
BOOST_OPAQUE_RING1(Final)
@@ -440,7 +440,7 @@
//////////////////////////////////////////////////////////////////////////////
- //~ template <class T, class U, typename Base = base_new_type >
+ //~ template <class T, class U, typename Base = base_opaque_type >
//~ struct ordered_ring_operators2
//~ : opaque::ring_operators2<T, U
//~ , opaque::totally_ordered2<T, U, Base
@@ -455,7 +455,7 @@
template <typename Bool=bool>
struct using_ordered_ring_operators1
{
- template <typename Final, typename Base = base_new_type>
+ template <typename Final, typename Base = base_opaque_type>
struct type : Base
{
BOOST_OPAQUE_ORDERED_RING1(Final,Bool)
@@ -464,7 +464,7 @@
//////////////////////////////////////////////////////////////////////////////
- //~ template <class T, class U, typename Base = base_new_type >
+ //~ template <class T, class U, typename Base = base_opaque_type >
//~ struct field_operators2
//~ : opaque::ring_operators2<T, U
//~ , opaque::dividable2<T, U
@@ -479,7 +479,7 @@
struct using_field_operators1
{
- template <typename Final, typename Base = base_new_type>
+ template <typename Final, typename Base = base_opaque_type>
struct type: Base
{
BOOST_OPAQUE_FIELD1(Final)
@@ -488,7 +488,7 @@
//////////////////////////////////////////////////////////////////////////////
- //~ template <class T, class U, typename Base = base_new_type >
+ //~ template <class T, class U, typename Base = base_opaque_type >
//~ struct ordered_field_operators2
//~ : opaque::field_operators2<T, U
//~ , opaque::totally_ordered2<T, U, Base
@@ -503,7 +503,7 @@
template <typename Bool=bool>
struct using_ordered_field_operators1
{
- template <typename Final, typename Base = base_new_type>
+ template <typename Final, typename Base = base_opaque_type>
struct type : Base
{
BOOST_OPAQUE_ORDERED_FIELD1(Final,Bool)
Modified: sandbox/opaque/boost/opaque/meta_mixin/inherited_from_underlying.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/meta_mixin/inherited_from_underlying.hpp (original)
+++ sandbox/opaque/boost/opaque/meta_mixin/inherited_from_underlying.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -16,22 +16,76 @@
#include <boost/opaque/meta_mixin/combined_operators.hpp>
namespace boost {
-namespace opaque {
+ namespace opaque {
- template <typename T, typename Bool=bool>
- struct inherited_from_underlying {
- template <typename Final, typename Base>
- struct type : Base
- {
- BOOST_OPAQUE_TOTALY_ORDERED1(Final,Bool)
- BOOST_OPAQUE_INTEGER_ARITHMETIC1(Final)
- BOOST_OPAQUE_BITWISE1(Final)
- BOOST_OPAQUE_UNIT_STEPABLE(Final)
- BOOST_OPAQUE_USING_UNARY_PLUS(Final)
- BOOST_OPAQUE_USING_UNARY_MINUS(Final)
- };
+ //! meta-mixin stating which operations are inherited from UT.
+ //! The user must specialize this meta-mixin to state which operations are inherited from UT.
+ //! This class must be specialized for specific types in order to make easier the construction of opaque types having UT as underlying type.
+ template <typename UT, typename Bool=bool>
+ struct inherited_from_underlying
+ {
+ template <typename Final, typename Base>
+ struct type : Base {
+
+ };
};
-}
+
+ //! Helper class to inherit from all the arithmetic operations.
+ template <typename Bool=bool>
+ struct inherited_from_arithmetic
+ {
+ template <typename Final, typename Base>
+ struct type : Base
+ {
+ BOOST_OPAQUE_TOTALY_ORDERED1(Final,Bool)
+ BOOST_OPAQUE_INTEGER_ARITHMETIC1(Final)
+ BOOST_OPAQUE_BITWISE1(Final)
+ BOOST_OPAQUE_UNIT_STEPABLE(Final)
+ BOOST_OPAQUE_USING_UNARY_PLUS(Final)
+ BOOST_OPAQUE_USING_UNARY_MINUS(Final)
+ };
+ };
+
+ //! inherited_from_underlying specializations for each one of the built-in types.
+ template <typename Bool>
+ struct inherited_from_underlying<char,Bool>
+ : inherited_from_arithmetic<Bool> { };
+ template <typename Bool>
+ struct inherited_from_underlying<short,Bool>
+ : inherited_from_arithmetic<Bool> { };
+ template <typename Bool>
+ struct inherited_from_underlying<int,Bool>
+ : inherited_from_arithmetic<Bool> { };
+ template <typename Bool>
+ struct inherited_from_underlying<long,Bool>
+ : inherited_from_arithmetic<Bool> { };
+ template <typename Bool>
+ struct inherited_from_underlying<long long,Bool>
+ : inherited_from_arithmetic<Bool> { };
+ template <typename Bool>
+ struct inherited_from_underlying<unsigned char,Bool>
+ : inherited_from_arithmetic<Bool> { };
+ template <typename Bool>
+ struct inherited_from_underlying<unsigned short,Bool>
+ : inherited_from_arithmetic<Bool> { };
+ template <typename Bool>
+ struct inherited_from_underlying<unsigned int,Bool>
+ : inherited_from_arithmetic<Bool> { };
+ template <typename Bool>
+ struct inherited_from_underlying<unsigned long,Bool>
+ : inherited_from_arithmetic<Bool> { };
+ template <typename Bool>
+ struct inherited_from_underlying<unsigned long long,Bool>
+ : inherited_from_arithmetic<Bool> { };
+ template <typename Bool>
+ struct inherited_from_underlying<float,Bool>
+ : inherited_from_arithmetic<Bool> { };
+ template <typename Bool>
+ struct inherited_from_underlying<double,Bool>
+ : inherited_from_arithmetic<Bool> { };
+
+
+ }
}
#endif
Modified: sandbox/opaque/boost/opaque/meta_mixin/linear_hierarchy.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/meta_mixin/linear_hierarchy.hpp (original)
+++ sandbox/opaque/boost/opaque/meta_mixin/linear_hierarchy.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -19,8 +19,8 @@
namespace boost {
namespace opaque {
- ////// implementation //////
- namespace opaque_detail{
+#ifndef BOOST_OPAQUE_DOXYGEN_INVOKED
+ namespace opaque_detail {
template<typename Final, typename State, typename MetaMixin>
struct do_inhetit : MetaMixin::template type< Final, State> {
@@ -35,6 +35,12 @@
};
}
+#endif
+
+ /** The linear_hierarchy metafunction gererates a linear hierarchy by folding the Mixins obtained by application of the MetaMixins in MetaMixinSeq.
+ *
+ * The nested type is equivalent to typename boost::mpl::fold<MetaMixinSeq, Base, implementation_defined<Final> >::type.
+ */
template<typename MetaMixinSeq, typename Final, typename Base>
struct linear_hierarchy {
Modified: sandbox/opaque/boost/opaque/meta_mixin/operators.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/meta_mixin/operators.hpp (original)
+++ sandbox/opaque/boost/opaque/meta_mixin/operators.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -10,20 +10,70 @@
//
//////////////////////////////////////////////////////////////////////////////
+/**
+ * @file
+ * This file includes meta-mixins that are used to add an operator overload forwarding from the final type to the underlying type.
+ *
+ * There is a meta-mixin for each one of the C++ overloadable operators.
+ * These meta-mixins have names that follows the naming used in <b>Boost.ConceptsTraits</b>, but prefixed by using_.
+ *
+ * <b>Arithmetic Operators</b>
+ *
+ * The arithmetic meta-mixins ease the task of creating a custom numeric type based on the underlying type.
+ * Given an underlying type, the templates add forward operators from the numeric class to the underlying type.
+ * These operations are like the ones the standard arithmetic types have, and may include comparisons, adding,
+ * incrementing, logical and bitwise manipulations, etc. Further, since most numeric types need more than one
+ * of these operators, some templates are provided to combine several of the basic operator templates in one
+ * declaration.
+ *
+ * The requirements for the types used to instantiate the simple operator templates are specified in terms of
+ * expressions which must be valid and the expression's return type.
+ *
+ * These meta-mixins are "simple" since they provide an operator based on a single operation the underlying type
+ * has to provide. They have an additional optional template parameter Base, which is not shown, for the base class
+ * chaining technique.
+ *
+ * In this section the meta-mixin follows the schema
+ *
+ * @code
+ * struct meta-mixin {
+ * template <typename NT, typename Base>
+ * struct type: Base {
+ * // Supplied Operation
+ * };
+ * };
+ * @endcode
+ *
+ * - @c NT/NT2 is expected to satisfy the <em>FinalUnderlying</em> requirements.
+ * - @c UT stands for @c NT::underlying_type.
+ * - @c UT2 stands for @c NT2::underlying_type.
+ * - @c this_ut is the instance @c UT reference obtained @c NT::underlying(this).
+ * - @c lhs is a @c NT/NT2 const reference.
+ * - @c rhs is a @c NT/NT2 const reference.
+ * - @c lhs_ut is the instance @c UT reference obtained @c lhs.underlying().
+ * - @c rhs_ut is the instance @c UT reference obtained @c rhs.underlying().
+ *
+
+
+
+ *
+ */
+
#ifndef BOOST_OPAQUE_OPERATORS_HPP
#define BOOST_OPAQUE_OPERATORS_HPP
#include <boost/operators.hpp>
namespace boost {
-namespace opaque {
+ namespace opaque {
//////////////////////////////////////////////////////////////////////////////
-#define BOOST_OPAQUE_HIDING_COPY_CONSTRUCTOR(T) \
+ #define BOOST_OPAQUE_HIDING_COPY_CONSTRUCTOR(T) \
private: \
T( const T& );
+ //!
struct hiding_copy_constructor {
template <typename Final, typename Base>
struct type : Base {
@@ -51,7 +101,10 @@
operator UT() const{ \
return Final::underlying(this); \
}
-
+ /**
+ * Adds the implicit conversion operator to the underlying type.
+ *
+ */
template <typename UT>
struct using_underlying_conversion {
template <typename Final, typename Base>
@@ -62,6 +115,7 @@
//////////////////////////////////////////////////////////////////////////////
+
template <typename T>
struct using_conversion_to {
template <typename Final, typename Base>
@@ -94,11 +148,16 @@
return Bool(Final::underlying(this) < rhs.underlying());\
}
+ /**
+ * Adds the <c>Bool operator<(const Final& rhs) const</c>.
+ *
+ * @Requires <c>Bool(Final::underlying(this) < rhs.underlying())</c> is correct.
+ */
template <typename Bool=bool>
struct using_less_than {
template <typename Final, typename Base>
struct type: Base {
- BOOST_OPAQUE_USING_LESS_THAN(Final,Bool)
+ BOOST_OPAQUE_USING_LESS_THAN(Final,Bool)
};
};
Modified: sandbox/opaque/boost/opaque/meta_mixin/transitive_explicit_substituable.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/meta_mixin/transitive_explicit_substituable.hpp (original)
+++ sandbox/opaque/boost/opaque/meta_mixin/transitive_explicit_substituable.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -18,71 +18,73 @@
#include <boost/type_traits/is_class.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include <boost/mpl/and.hpp>
+#include <boost/conversion/convert_to.hpp>
namespace boost {
-namespace opaque {
+ namespace opaque {
+#if !defined(BOOST_OPAQUE_DOXYGEN_INVOKED)
template <typename BaseClass, typename UT>
- struct transitive_explicit_substituable;
+ struct using_explicit_conversion_to_underlying_type_hierarchy;
namespace opaque_detail {
- template <
+ template <
typename BaseClass,
typename Final,
typename UT,
typename Base,
bool B>
- struct transitive_explicit_substituable_next_level;
+ struct transitive_explicit_substituable_next_level;
- template <
+ template <
typename BaseClass,
typename Final,
typename UT,
typename Base>
- struct transitive_explicit_substituable_next_level<BaseClass, Final, UT, Base, true>
- : transitive_explicit_substituable<BaseClass, typename UT::underlying_type>
- ::template type<Final, Base>
- {};
- template <
+ struct transitive_explicit_substituable_next_level<BaseClass, Final, UT, Base, true>
+ : using_explicit_conversion_to_underlying_type_hierarchy<BaseClass, typename UT::underlying_type>
+ ::template type<Final, Base>
+ {};
+ template <
typename BaseClass,
typename Final,
typename UT,
typename Base
- >
- struct transitive_explicit_substituable_next_level<BaseClass, Final, UT, Base, false>
- : Base
- {};
+ >
+ struct transitive_explicit_substituable_next_level<BaseClass, Final, UT, Base, false>
+ : Base
+ {};
}
- namespace dummy {
- template <typename T> struct base_tag {};
- template <typename T> struct type_tag : public base_tag<T> {};
- }
+#endif
+ //! mixin generating the explicit conversion to all the underlying types hierarchy.
+ //! This meta-mixin provides the Final class explicit conversions for all the underlying types hierarchy
+ //! (when the compiler supports explicit conversion operators).
+ //! For portability purposed the library provide as workaround a @c convert_to non member function which follows the Boost.conversion protocol.
template <typename BaseClass, typename UT>
- struct transitive_explicit_substituable {
- template <typename Final, typename Base>
- struct type
- : opaque_detail::transitive_explicit_substituable_next_level<BaseClass, Final, UT, Base,
- mpl::and_<is_class<UT>, is_base_of<BaseClass, UT> >::value>
+ struct using_explicit_conversion_to_underlying_type_hierarchy {
+ template <typename Final, typename Base>
+ struct type
+ : opaque_detail::transitive_explicit_substituable_next_level<BaseClass, Final, UT, Base,
+ mpl::and_<is_class<UT>, is_base_of<BaseClass, UT> >::value>
+ {
+ friend UT convert_to(Final const& rhs,
+ boost::dummy::type_tag<UT> const&)
+ {
+ return Final::final(&rhs).underlying();
+ }
+#if !defined(BOOST_NO_EXPLICIT_CONVERSION_OPERATORS)
+ explicit operator UT() const
{
- #if defined(BOOST_NO_EXPLICIT_CONVERSION_OPERATORS)
- friend UT convert_to(Final const& rhs,
- boost::opaque::dummy::type_tag<UT> const&)
- {
- return Final::final(&rhs).underlying();
- }
- #else
- explicit operator UT() const
- {
- return Final::final(this).underlying();
- }
- #endif
- };
+ return Final::final(this).underlying();
+ }
+#endif
+ };
};
-}
+ }
}
Modified: sandbox/opaque/boost/opaque/meta_mixin/transitive_substituable.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/meta_mixin/transitive_substituable.hpp (original)
+++ sandbox/opaque/boost/opaque/meta_mixin/transitive_substituable.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -18,56 +18,57 @@
#include <boost/mpl/and.hpp>
namespace boost {
-namespace opaque {
+ namespace opaque {
template <typename BaseClass, typename UT>
- struct transitive_substituable;
+ struct using_implicit_conversion_to_underlying_type_hierarchy;
namespace opaque_detail {
- template <
+ template <
typename BaseClass,
typename Final,
typename UT,
typename Base,
bool IsConvertible
- >
- struct transitive_substituable_next_level;
+ >
+ struct transitive_substituable_next_level;
- template <
+ template <
typename BaseClass,
typename Final,
typename UT,
typename Base
- >
- struct transitive_substituable_next_level<BaseClass, Final, UT, Base, true>
- : transitive_substituable<BaseClass, typename UT::underlying_type>
- ::template type<Final, Base>
- { };
-
- template <typename BaseClass, typename Final, typename UT, typename Base>
- struct transitive_substituable_next_level<BaseClass, Final, UT, Base, false>
- : Base
- { };
+ >
+ struct transitive_substituable_next_level<BaseClass, Final, UT, Base, true>
+ : using_implicit_conversion_to_underlying_type_hierarchy<BaseClass, typename UT::underlying_type>
+ ::template type<Final, Base>
+ { };
+
+ template <typename BaseClass, typename Final, typename UT, typename Base>
+ struct transitive_substituable_next_level<BaseClass, Final, UT, Base, false>
+ : Base
+ { };
}
+ //! mixin generating the implicit conversion to all the underlying type hierarchy.
template <typename BaseClass, typename UT>
- struct transitive_substituable {
- template <typename Final, typename Base>
- struct type
- : opaque_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();
- }
- };
+ struct using_implicit_conversion_to_underlying_type_hierarchy {
+ template <typename Final, typename Base>
+ struct type
+ : opaque_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
Modified: sandbox/opaque/boost/opaque/new_class.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/new_class.hpp (original)
+++ sandbox/opaque/boost/opaque/new_class.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -10,76 +10,170 @@
//
//////////////////////////////////////////////////////////////////////////////
+
+/**
+ * @File Defines the new_class<> class.
+ */
+
+
#ifndef BOOST_OPAQUE_NEW_CLASS_HPP
#define BOOST_OPAQUE_NEW_CLASS_HPP
#include <boost/opaque/meta_mixin/linear_hierarchy.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>
+#include <boost/mpl/push_front.hpp>
namespace boost {
-namespace opaque {
+ namespace opaque {
+
+ namespace opaque_detail {
- class base_new_type {};
+ template <typename T, bool B>
+ struct build_undelying_type_hierarchy;
+
+ template <typename T>
+ struct build_undelying_type_hierarchy<T,true> {
+ typedef typename mpl::push_front<typename T::undelying_type_hierarchy, T
+ >::type type;
+ };
+
+ template <typename T>
+ struct build_undelying_type_hierarchy<T,false> {
+ typedef mpl::vector<T> type;
+ };
+ }
+ //! base types for all the new opaque types, used to identify them
+ struct base_opaque_type {};
+
+ //! new_class<> wraps an underlying type providing the regular constructors and copy construction from the underlying type and all the convertibles to the the UT.
+ //!
+ //! @Requires
+ //! @li @c Final must publicly inherit from this class to make it a model of <em>FinalUnderlying</em>
+ //! @li @c UT must be <em>CopyConstructible</em> and <em>Assignable</em>.
+ //! @li @c MetaMixinSeq must be a model of <em>MetaMixinSeq</em>.
+ //! @li @c Base must inherit directly or indirectly from @c base_opaque_type or be @c base_opaque_type.
+ //!
+ //! @Note
+ //! @li Can instances of UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of convertible to UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of UT be implicitly converted to instances of OT? No, this is one of the main differentiating features of @c new_class.
+ //! @li Can instances of OT be explicitly converted to instances of UT? Yes, there is an explicit conversion operator (if supported by the compiler) or the @c underlying function.
+ //! @li Can instances of OT be implicitly converted to instances of UT? No, this is one of the main differentiating features of @c new_class.
template <
- typename Final,
- typename T,
- typename MetaMixinSeq=boost::mpl::vector0<>,
- typename Base=base_new_type
+ typename Final,
+ typename UT,
+ typename MetaMixinSeq=boost::mpl::vector0<>,
+ typename Base=base_opaque_type
>
class new_class : public linear_hierarchy<MetaMixinSeq, Final, Base>::type
{
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) {}
+ //! the underlying type
+ //!
+ typedef UT underlying_type;
+
+ //! MPL sequence of type to which this type is convertible.
+ typedef typename opaque_detail::build_undelying_type_hierarchy<UT,
+ mpl::and_<
+ is_class<UT>,
+ is_base_of<base_opaque_type,UT>
+ >::value
+ >::type undelying_type_hierarchy;
+
+
+ //! default constructor
+ new_class() : val_() {}
+ //! copy constructor
+ new_class(const new_class & rhs) : val_(rhs.val_) {}
+ //! explicit construction from the underlying type
+ explicit new_class(UT v) : val_(v) {}
+ //! explicit construction from convertible to the underlying type
+ template <typename W>
+ explicit new_class(W v) : val_(v) {}
protected:
- T val_;
+ //! the storage
+ //!
+ UT val_;
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>
- static Final& final(F* f) {
- return static_cast<Final&>(*f);
- }
+ //! explicit conversion to the underlying type.
+ underlying_type const& underlying() const {
+ return val_;
+ }
+ //! explicit conversion to the underlying type.
+ underlying_type& underlying() {
+ return val_;
+ }
+#if !defined(BOOST_NO_EXPLICIT_CONVERSION_OPERATORS)
+ //! explicit conversion operator to the underlying type.
+ //!
+ //! @Remark Only provided when supported by the compiler.
+ //! @Note the @explicit keyword doesn't appears in the documentation as doxygen doesn't generates it :(.
+ explicit operator underlying_type const&() const {
+ return val_;
+ }
+ //! explicit conversion operator to the underlying type.
+ //!
+ //! @Remark Only provided when supported by the compiler.
+ //! @Note the @explicit keyword doesn't appears in the documentation as doxygen doesn't generates it :(.
+ explicit operator underlying_type&() {
+ return val_;
+ }
+
+#endif
+
+ //! explicit conversion from a @c Final class to the underlying type.
+ template<typename F>
+ static underlying_type& underlying(F* f){
+ return final(f).underlying();
+ }
+
+ //! explicit conversion from a <c>Final const</c> class to the underlying type.
+ template<typename F>
+ static underlying_type const& underlying(F const* f){
+ return final(f).underlying();
+ }
+
+ //! explicit conversion from a base const class to the @c Final class.
+ template<typename F>
+ static Final const& final(F const* f) {
+ return static_cast<Final const&>(*f);
+ }
+ //! explicit conversion from a base class to the @c Final class.
+ template<typename F>
+ static Final& final(F* f) {
+ return static_cast<Final&>(*f);
+ }
};
}
- template <
- typename T,
- typename Final,
- typename UT,
- typename MetaMixinSeq,
- typename Base
- >
- T opaque_static_cast(opaque::new_class<Final, UT, MetaMixinSeq, Base> const& v)
- {
- return static_cast<T>(v.underlying());
- }
+ //! Conversion from a @c new_class<> to a type convertible from @c UT.
+
+ //! @Requires
+ //! @li @c Final must publicly inherit from opaque::new_class<Final, UT, MetaMixinSeq, Base>.
+ //! @li @c UT must be <em>CopyConstructible</em> and <em>Assignable</em>.
+ //! @li @c MetaMixinSeq must be a model of <em>MetaMixinSeq</em>.
+ //! @li @c UT must be convertible to @c T.
+ //! @li @c Base must inherit directly or indirectly from @c base_opaque_type or be @c base_opaque_type.
+
+ template <
+ typename T,
+ typename Final,
+ typename UT,
+ typename MetaMixinSeq,
+ typename Base
+ >
+ T opaque_static_cast(opaque::new_class<Final, UT, MetaMixinSeq, Base> const& v)
+ {
+ return static_cast<T>(v.underlying());
+ }
}
Modified: sandbox/opaque/boost/opaque/new_class_macro.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/new_class_macro.hpp (original)
+++ sandbox/opaque/boost/opaque/new_class_macro.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -18,7 +18,26 @@
#include <boost/opaque/macros.hpp>
#include <boost/preprocessor/seq/enum.hpp>
-#define BOOST_OPAQUE_NEW_CLASS(NC, UT,MMSEQ) \
+
+/**
+
+ @brief
+
+ @Params
+ @Param{NC,the new class to be defined }
+ @Param{UT,the underlying type}
+ @Param{MMSEQ,the META_MIXIN_SEQ sequence}
+
+ @Result If @c MMSEQ is <c>( (MM1) ... ((MMn) )</c>
+ @code
+ boost::opaque::new_class< NC, UT,
+ boost::mpl::vector<MM1, ..., MMn>
+ >
+ @endcode
+
+ */
+
+#define BOOST_OPAQUE_NEW_CLASS(NC, UT, MMSEQ) \
boost::opaque::new_class< NC, UT, \
boost::mpl::vector< \
BOOST_PP_SEQ_ENUM(MMSEQ) \
Modified: sandbox/opaque/boost/opaque/new_type.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/new_type.hpp (original)
+++ sandbox/opaque/boost/opaque/new_type.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -17,42 +17,66 @@
#include <boost/mpl/vector.hpp>
namespace boost {
-namespace opaque {
-
-
+ namespace opaque {
+
+ //! @c new_type<> provides the equivalent of @c new_class<> but can be used as a @c typedef.
+ //!
+ //! @Requires
+ //! @li @c UT must be <em>CopyConstructible</em> and <em>Assignable</em>.
+ //! @li @c MetaMixinSeq must be a model of <em>MetaMixinSeq</em>.
+ //! @li @c Base must inherit directly or indirectly from @c base_opaque_type or be @c base_opaque_type.
+ //!
+ //! @Note
+ //! @li Can instances of UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of convertible to UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of UT be implicitly converted to instances of OT? No, this is one of the main differentiating features of @c new_class.
+ //! @li Can instances of OT be explicitly converted to instances of UT? Yes, there is an explicit conversion operator (if supported by the compiler) or the @c underlying function.
+ //! @li Can instances of OT be implicitly converted to instances of UT? No, this is one of the main differentiating features of @c new_class.
template <
- typename T,
- typename Tag,
- typename MetaMixinSeq=boost::mpl::vector0<>,
- typename Base=base_new_type
+ typename UT,
+ typename Tag,
+ typename MetaMixinSeq=boost::mpl::vector0<>,
+ typename Base=base_opaque_type
>
class new_type
- : public new_class<new_type<T, Tag, MetaMixinSeq, Base>,
- T, MetaMixinSeq, Base>
+ : public new_class<new_type<UT, Tag, MetaMixinSeq, Base>, UT, MetaMixinSeq, Base>
{
- typedef new_class<new_type<T, Tag, MetaMixinSeq, Base>,
- T, MetaMixinSeq, Base> base_type;
+ typedef new_class<new_type<UT, Tag, MetaMixinSeq, Base>, UT, MetaMixinSeq, Base> base_type;
public:
- template <typename W>
- explicit new_type(W v) : base_type(v) {}
- new_type(){}
- new_type(const new_type & rhs) : base_type(rhs.val_) {}
- explicit new_type(T v) : base_type(v) {}
-
+ //! default constructor
+ new_type() {}
+ //! copy constructor
+ new_type(const new_type & rhs) : base_type(rhs.val_) {}
+ //! explicit construction from the underlying type
+ explicit new_type(UT v) : base_type(v) {}
+ //! explicit construction from convertible to the underlying type
+ template <typename W>
+ explicit new_type(W v) : base_type(v) {}
+
};
}
- template <
- typename T,
- typename UT,
- typename Tag,
- typename MetaMixinSeq,
- typename Base
- >
- T opaque_static_cast(opaque::new_type<UT,Tag,MetaMixinSeq,Base> const& v)
- {
- return static_cast<T>(v.underlying());
- }
+ //! Conversion from a @c new_type<> to a type convertible from @c UT.
+
+ //! @Requires
+ //! @li @c Final must publicly inherit from opaque::new_class<Final, UT, MetaMixinSeq, Base>.
+ //! @li @c UT must be <em>CopyConstructible</em> and <em>Assignable</em>.
+ //! @li @c MetaMixinSeq must be a model of <em>MetaMixinSeq</em>.
+ //! @li @c UT must be convertible to @c T.
+ //! @li @c Base must inherit directly or indirectly from @c base_opaque_type or be @c base_opaque_type.
+
+ template <
+ typename T,
+ typename UT,
+ typename Tag,
+ typename MetaMixinSeq,
+ typename Base
+ >
+ T opaque_static_cast(opaque::new_type<UT,Tag,MetaMixinSeq,Base> const& v)
+ {
+ return static_cast<T>(v.underlying());
+ }
+
}
Modified: sandbox/opaque/boost/opaque/new_type_macro.hpp
==============================================================================
--- sandbox/opaque/boost/opaque/new_type_macro.hpp (original)
+++ sandbox/opaque/boost/opaque/new_type_macro.hpp 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -17,6 +17,25 @@
#include <boost/opaque/new_type.hpp>
#include <boost/preprocessor/seq/enum.hpp>
+/**
+
+ @brief Generates the code to define a new typedef.
+
+ @Params
+ @Param{UT,the underlying type}
+ @Param{NT,the new type to be defined }
+ @Param{MMSEQ,the META_MIXIN_SEQ sequence}
+
+ @Result If @c MMSEQ is <c>( (MM1) ... ((MMn) )</c>
+ @code
+ struct NC_tag {};
+ typedef boost::opaque::new_type< UT, NC_tag,
+ boost::mpl::vector<MM1, ..., MMn>
+ > NT
+ @endcode
+
+ */
+
#define BOOST_OPAQUE_NEW_TYPE(UT,NT,MMSEQ) \
struct BOOST_JOIN(NT,_tag){}; \
typedef boost::opaque::new_type< UT, BOOST_JOIN(NT,_tag), \
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 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -13,12 +13,7 @@
#ifndef BOOST_OPAQUE_PRIVATE_OPAQUE_CLASS_HPP
#define BOOST_OPAQUE_PRIVATE_OPAQUE_CLASS_HPP
-//~ 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
+
#include <boost/opaque/meta_mixin/inherited_from_underlying.hpp>
#include <boost/opaque/meta_mixin/transitive_explicit_substituable.hpp>
@@ -29,55 +24,83 @@
#include <boost/mpl/push_front.hpp>
namespace boost {
-namespace opaque {
- class base_private_opaque_type {};
+ namespace opaque {
+
+ //! base types for all the private_opaque_class, used to identify them.
+ struct base_private_opaque_type : base_opaque_type {};
+
+ //! private_opaque_class<> wraps an underlying type providing the regular
+ //! constructors and copy construction from the underlying type and all the
+ //! conversions to the the UT inheriting from all the underlying operations.
+ //!
+ //! @Requires
+ //! @li @c Final must publicly inherit from this class.
+ //! @li @c UT must be <em>CopyConstructible</em>.
+ //! @li @c Bool must be a model of <em>Boolean</em>.
+ //! @li @c MetaMixinSeq must be a model of <em>MetaMixinSeq</em>.
+ //! @li @c Base must inherit directly or indirectly from @c base_opaque_type or be @c base_opaque_type.
+ //!
+ //! @Note
+ //! @li Can instances of UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of convertible to UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of UT be implicitly converted to instances of OT? No, this is one of the main differentiating features of opaque types.
+ //! @li Can instances of OT be explicitly converted to instances of UT? Yes, there is an explicit conversion operator (if supported by the compiler) or the @c underlying function.
+ //! @li Can instances of OT be implicitly converted to instances of UT? No, this is one of the main differentiating features of @c base_private_opaque_type.
+ //!
+ //! @c private_opaque_class<> is a @c new_class with the @c using_explicit_conversion_to_underlying_type_hierarchy<base_private_opaque_type>
+ //! and @c inherited_from_underlying<UT> added to the sequence of meta-mixins @c MetaMixinSeq, so a @c private_opaque_class
+ //! inherits from all the operations of the underlying type @c UT and adds transitive explicit conversions to all the substituables.
template <
- typename Final,
- typename T,
- typename Bool=bool,
- typename MetaMixinSeq=boost::mpl::vector0<>,
- typename Base=base_private_opaque_type
+ typename Final,
+ typename UT,
+ typename Bool=bool,
+ typename MetaMixinSeq=boost::mpl::vector0<>,
+ typename Base=base_private_opaque_type
>
class private_opaque_class
- : public
- new_class< Final, T,
- typename mpl::push_front<
- typename mpl::push_front<
- MetaMixinSeq,
- opaque::transitive_explicit_substituable<base_private_opaque_type, T>
- >::type,
- opaque::inherited_from_underlying<T,Bool>
- >::type, Base
- >
+ : public
+ new_class< Final, UT,
+ typename mpl::push_front<
+ typename mpl::push_front<
+ MetaMixinSeq,
+ using_explicit_conversion_to_underlying_type_hierarchy<base_private_opaque_type, UT>
+ >::type,
+ inherited_from_underlying<UT,Bool>
+ >::type, Base
+ >
{
- typedef
- new_class< Final, T,
- typename mpl::push_front<
- typename mpl::push_front<
- MetaMixinSeq,
- opaque::transitive_explicit_substituable<base_private_opaque_type, T>
- >::type,
- opaque::inherited_from_underlying<T,Bool>
- >::type, Base
- >
- base_type;
+ typedef
+ new_class< Final, UT,
+ typename mpl::push_front<
+ typename mpl::push_front<
+ MetaMixinSeq,
+ using_explicit_conversion_to_underlying_type_hierarchy<base_private_opaque_type, UT>
+ >::type,
+ opaque::inherited_from_underlying<UT,Bool>
+ >::type, Base
+ >
+ base_type;
public:
-
- private_opaque_class() {};
- private_opaque_class(const private_opaque_class & 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)
- {}
+ //! default constructor
+ private_opaque_class() {};
+ //! copy constructor
+ private_opaque_class(const private_opaque_class & rhs)
+ : base_type(rhs.val_) {}
+ //! implicit construction from the @c Final
+ private_opaque_class(const Final & rhs)
+ : base_type(rhs.val_) {}
+ //! explicit construction from the underlying type
+ explicit private_opaque_class(UT v)
+ : base_type(v) {};
+ //! explicit construction from convertible to the underlying type
+ template <typename W>
+ explicit private_opaque_class(W 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 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -15,45 +15,54 @@
#include <boost/opaque/private_opaque_class.hpp>
- //~ 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
-
namespace boost {
-namespace opaque {
+ namespace opaque {
+
+ //! @c private_opaque_type<> provides the equivalent of @c private_opaque_class<> but can be used as a @c typedef.
+ //!
+ //! @Requires
+ //! @li @c UT must be <em>CopyConstructible</em>.
+ //! @li @c MetaMixinSeq must be a model of <em>MetaMixinSeq</em>.
+ //! @li @c Base must inherit directly or indirectly from @c base_opaque_type or be @c base_opaque_type.
+ //!
+ //! @Note
+ //! @li Can instances of UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of convertible to UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of UT be implicitly converted to instances of OT? No, this is one of the main differentiating features of @c new_class.
+ //! @li Can instances of OT be explicitly converted to instances of UT? Yes, there is an explicit conversion operator (if supported by the compiler) or the @c underlying function.
+ //! @li Can instances of OT be implicitly converted to instances of UT? No, this is one of the main differentiating features of @c private_opaque_type.
template <
- typename T,
- typename Tag=void,
- typename Bool=bool,
- typename MetaMixinSeq=boost::mpl::vector0<>,
- typename Base=base_private_opaque_type
+ typename UT,
+ typename Tag=void,
+ typename Bool=bool,
+ typename MetaMixinSeq=boost::mpl::vector0<>,
+ typename Base=base_private_opaque_type
>
class private_opaque_type : public
- private_opaque_class< private_opaque_type<T,Tag,Bool,MetaMixinSeq,Base>,
- T, Bool, MetaMixinSeq, Base>
+ private_opaque_class< private_opaque_type<UT,Tag,Bool,MetaMixinSeq,Base>,
+ UT, Bool, MetaMixinSeq, Base>
{
- typedef
- private_opaque_class< private_opaque_type<T,Tag,Bool,MetaMixinSeq,Base>,
- T, Bool, MetaMixinSeq, Base>
- base_type;
+ typedef
+ private_opaque_class< private_opaque_type<UT,Tag,Bool,MetaMixinSeq,Base>,
+ UT, Bool, MetaMixinSeq, Base>
+ base_type;
public:
- private_opaque_type() {};
- private_opaque_type(const private_opaque_type & rhs)
- : base_type(rhs.val_) {}
- explicit private_opaque_type(T v)
- : base_type(v) {};
- template <typename W>
- explicit private_opaque_type(W v)
- : base_type(v)
- {}
+ private_opaque_type() {};
+ private_opaque_type(const private_opaque_type & rhs)
+ : base_type(rhs.val_) {}
+ //! explicit construction from the underlying type
+ explicit private_opaque_type(UT v)
+ : base_type(v) {};
+ //! explicit construction from convertible to the underlying type
+ template <typename W>
+ explicit private_opaque_type(W v)
+ : base_type(v)
+ {}
};
-}
+ }
}
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 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -13,93 +13,86 @@
#ifndef BOOST_OPAQUE_PUBLIC_OPAQUE_CLASS_HPP
#define BOOST_OPAQUE_PUBLIC_OPAQUE_CLASS_HPP
- //~ 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
-
#include <boost/opaque/meta_mixin/inherited_from_underlying.hpp>
#include <boost/opaque/meta_mixin/transitive_substituable.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>
-#include <boost/mpl/push_front.hpp>
namespace boost {
-namespace opaque {
-
- class base_public_opaque_type {};
+ namespace opaque {
- template <typename T, bool B>
- struct get_substituables;
-
- template <typename T>
- struct get_substituables<T,true> {
- typedef typename mpl::push_front<typename T::substituables, T
- >::type type;
- };
+ //! base types for all the private_opaque_class, used to identify them.
+ struct base_public_opaque_type : base_opaque_type {};
- template <typename T>
- struct get_substituables<T,false> {
- typedef mpl::vector<T> type;
- };
-
+ //! public_opaque_class<> wraps an underlying type providing the regular
+ //! constructors and copy construction from the underlying type and all the
+ //! conversions to the the UT inheriting from all the underlying operations.
+ //!
+ //! @Requires
+ //! @li @c Final must publicly inherit from this class.
+ //! @li @c UT must be <em>CopyConstructible</em>.
+ //! @li @c Bool must be a model of <em>Boolean</em>.
+ //! @li @c MetaMixinSeq must be a model of <em>MetaMixinSeq</em>.
+ //! @li @c Base must inherit directly or indirectly from @c base_opaque_type or be @c base_opaque_type.
+ //!
+ //! @Note
+ //! @li Can instances of UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of convertible to UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of UT be implicitly converted to instances of OT? No, this is one of the main differentiating features of opaque types.
+ //! @li Can instances of OT be explicitly converted to instances of UT? Yes, there is an explicit conversion operator (if supported by the compiler) or the @c underlying function.
+ //! @li Can instances of OT be implicitly converted to instances of UT? Yes, this is one of the main differentiating features of @c public_opaque_class.
+ //!
+ //! @c public_opaque_class<> is a @c new_class with the @c using_implicit_conversion_to_underlying_type_hierarchy<base_public_opaque_type>
+ //! and @c inherited_from_underlying<UT> added to the sequence of meta-mixins @c MetaMixinSeq,
+ //! so a @c public_opaque_type inherits from all the operations of the underlying type @c UT and
+ //! adds implicit conversions to all the types in the underlying type hierarchy.
template <
- typename Final,
- typename T,
- typename Bool=bool,
- typename MetaMixinSeq=boost::mpl::vector0<>,
- typename Base=base_public_opaque_type
+ typename Final,
+ typename T,
+ typename Bool=bool,
+ typename MetaMixinSeq=boost::mpl::vector0<>,
+ typename Base=base_public_opaque_type
>
class public_opaque_class
- : public
- new_class< Final, T,
- typename mpl::push_front<
- typename mpl::push_front<
- MetaMixinSeq,
- opaque::transitive_substituable<base_public_opaque_type, T>
- >::type,
- opaque::inherited_from_underlying<T,Bool>
- >::type, Base
- >
+ : public
+ new_class< Final, T,
+ typename mpl::push_front<
+ typename mpl::push_front<
+ MetaMixinSeq,
+ using_implicit_conversion_to_underlying_type_hierarchy<base_public_opaque_type, T>
+ >::type,
+ opaque::inherited_from_underlying<T,Bool>
+ >::type, Base
+ >
{
- typedef
- new_class< Final, T,
+ typedef
+ new_class< Final, T,
typename mpl::push_front<
- typename mpl::push_front<
- MetaMixinSeq,
- opaque::transitive_substituable<base_public_opaque_type, T>
- >::type,
- opaque::inherited_from_underlying<T,Bool>
+ typename mpl::push_front<
+ MetaMixinSeq,
+ using_implicit_conversion_to_underlying_type_hierarchy<base_public_opaque_type, T>
+ >::type,
+ opaque::inherited_from_underlying<T,Bool>
>::type, Base
- >
- base_type;
+ >
+ base_type;
public:
- typedef typename get_substituables<T,
- mpl::and_< is_class<T>,
- is_base_of<base_public_opaque_type,T>
- >::value
- >::type substituables;
-
-
- public_opaque_class() {}
- public_opaque_class(const public_opaque_class & 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) {}
+ public_opaque_class() {}
+ public_opaque_class(const public_opaque_class & rhs)
+ : base_type(rhs.val_){}
+ public_opaque_class(const Final & rhs)
+ : base_type(rhs.val_){}
+ //! explicit construction from the underlying type
+ explicit public_opaque_class(T v)
+ : base_type(v) {}
+ //! explicit construction from convertible to the underlying type
+ template <typename W>
+ explicit public_opaque_class(W v)
+ : base_type(v) {}
};
-}
+ }
}
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 2011-03-27 09:22:02 EDT (Sun, 27 Mar 2011)
@@ -13,45 +13,60 @@
#ifndef BOOST_OPAQUE_PUBLIC_OPAQUE_TYPE_HPP
#define BOOST_OPAQUE_PUBLIC_OPAQUE_TYPE_HPP
- //~ 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
+//~ 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
#include <boost/opaque/public_opaque_class.hpp>
namespace boost {
-namespace opaque {
+ namespace opaque {
+ //! @c public_opaque_type<> provides the equivalent of @c public_opaque_class<> but can be used as a @c typedef.
+ //!
+ //! @Requires
+ //! @li @c UT must be <em>CopyConstructible</em>.
+ //! @li @c MetaMixinSeq must be a model of <em>MetaMixinSeq</em>.
+ //! @li @c Base must inherit directly or indirectly from @c base_opaque_type or be @c base_opaque_type.
+ //!
+ //! @Note
+ //! @li Can instances of UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of convertible to UT be explicitly converted to instances of OT? Yes, there is an explicit constructor.
+ //! @li Can instances of UT be implicitly converted to instances of OT? No, this is one of the main differentiating features of @c new_class.
+ //! @li Can instances of OT be explicitly converted to instances of UT? Yes, there is an explicit conversion operator (if supported by the compiler) or the @c underlying function.
+ //! @li Can instances of OT be implicitly converted to instances of UT? Yes, this is one of the main differentiating features of @c public_opaque_type.
template <
- typename T,
- typename Tag=void,
- typename Bool=bool,
- typename MetaMixinSeq=boost::mpl::vector0<>,
- typename Base=base_public_opaque_type
+ typename T,
+ typename Tag=void,
+ typename Bool=bool,
+ typename MetaMixinSeq=boost::mpl::vector0<>,
+ typename Base=base_public_opaque_type
>
class public_opaque_type
- : public
- public_opaque_class< public_opaque_type<T,Tag,Bool,MetaMixinSeq,Base>,
- T, Bool, MetaMixinSeq, Base>
+ : public
+ public_opaque_class< public_opaque_type<T,Tag,Bool,MetaMixinSeq,Base>,
+ T, Bool, MetaMixinSeq, Base>
{
- typedef
- public_opaque_class< public_opaque_type<T,Tag,Bool,MetaMixinSeq,Base>,
- T, Bool, MetaMixinSeq, Base> base_type;
+ typedef
+ public_opaque_class< public_opaque_type<T,Tag,Bool,MetaMixinSeq,Base>,
+ T, Bool, MetaMixinSeq, Base> base_type;
public:
- public_opaque_type() {}
- public_opaque_type(const public_opaque_type & 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) {}
+ public_opaque_type() {}
+ public_opaque_type(const public_opaque_type & rhs)
+ : base_type(rhs.val_) {}
+ //! explicit construction from the underlying type
+ explicit public_opaque_type(T v)
+ : base_type(v) {}
+ //! explicit construction from convertible to the underlying type
+ 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