Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72250 - sandbox/opaque/boost/opaque/meta_mixin
From: vicente.botet_at_[hidden]
Date: 2011-05-28 15:44:31


Author: viboes
Date: 2011-05-28 15:44:30 EDT (Sat, 28 May 2011)
New Revision: 72250
URL: http://svn.boost.org/trac/boost/changeset/72250

Log:
Opaque: Added placeholder
Added:
   sandbox/opaque/boost/opaque/meta_mixin/placeholder.hpp (contents, props changed)
Text files modified:
   sandbox/opaque/boost/opaque/meta_mixin/linear_hierarchy.hpp | 2
   sandbox/opaque/boost/opaque/meta_mixin/operators.hpp | 128 +++++++++++++++++++++++++++++++++++++--
   2 files changed, 120 insertions(+), 10 deletions(-)

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-05-28 15:44:30 EDT (Sat, 28 May 2011)
@@ -42,7 +42,7 @@
     }
 #endif
 
- /** The linear_hierarchy metafunction gererates a linear hierarchy by folding the Mixins obtained by application of the MetaMixins in MetaMixinSeq.
+ /** The linear_hierarchy metafunction generates 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.
      */

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-05-28 15:44:30 EDT (Sat, 28 May 2011)
@@ -64,6 +64,7 @@
 #if !defined(BOOST_OPAQUE_DOXYGEN_INVOKED)
 
 #include <boost/config.hpp>
+#include <boost/opaque/meta_mixin/placeholder.hpp>
 #if !defined(BOOST_OPAQUE_NOT_DEPENDS_ON_CONVERSION)
 #include <boost/conversion/convert_to.hpp>
 #endif
@@ -174,7 +175,99 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
-#define BOOST_OPAQUE_DCL_META_MIXIN_REL(OP, NAME) \
+#define BOOST_OPAQUE_DCL_META_MIXIN_REL2(OP, NAME) \
+ template <typename Bool=bool, typename T=_self, typename U=_self> \
+ struct BOOST_JOIN(using_,NAME); \
+ template <typename Bool=bool, typename T=_self, typename U=_self> \
+ struct BOOST_JOIN(hiding_,NAME); \
+ template <typename Bool> \
+ struct BOOST_JOIN(using_,NAME)<Bool, _self, _self> \
+ { \
+ template <typename Final, typename Base> \
+ struct type: Base \
+ { \
+ protected:\
+ static Bool BOOST_OPAQUE_INTERNAL_NAME(NAME) (const Final& lhs, const Final& rhs) \
+ { \
+ return Bool(lhs.underlying() OP rhs.underlying()); \
+ } \
+ public: \
+ friend bool operator OP (Final const& lhs, Final const& rhs) \
+ { \
+ return Final::BOOST_OPAQUE_INTERNAL_NAME(NAME)(lhs, rhs);\
+ } \
+ }; \
+ }; \
+ template <typename Bool> \
+ struct BOOST_JOIN(hiding_,NAME)<Bool, _self, _self> \
+ { \
+ template <typename Final, typename Base> \
+ struct type: Base \
+ { \
+ private:\
+ static Bool BOOST_OPAQUE_INTERNAL_NAME(NAME) (const Final& lhs, const Final& rhs); \
+ }; \
+ }; \
+ template <typename Bool, typename T> \
+ struct BOOST_JOIN(using_,NAME)<Bool, T, _self> \
+ { \
+ template <typename Final, typename Base> \
+ struct type: Base \
+ { \
+ protected:\
+ static Bool BOOST_OPAQUE_INTERNAL_NAME(NAME) (const T& lhs, const Final& rhs) \
+ { \
+ return Bool(lhs OP rhs.underlying()); \
+ } \
+ public: \
+ friend bool operator OP (T const& lhs, Final const& rhs) \
+ { \
+ return Final::BOOST_OPAQUE_INTERNAL_NAME(NAME)(lhs, rhs);\
+ } \
+ }; \
+ }; \
+ template <typename Bool, typename T> \
+ struct BOOST_JOIN(hiding_,NAME)<Bool, T, _self> \
+ { \
+ template <typename Final, typename Base> \
+ struct type: Base \
+ { \
+ private:\
+ static Bool BOOST_OPAQUE_INTERNAL_NAME(NAME) (const T& lhs, const Final& rhs); \
+ }; \
+ }; \
+ template <typename Bool, typename T> \
+ struct BOOST_JOIN(using_,NAME)<Bool, _self, T> \
+ { \
+ template <typename Final, typename Base> \
+ struct type: Base \
+ { \
+ protected:\
+ static Bool BOOST_OPAQUE_INTERNAL_NAME(NAME) (const Final& lhs, const T& rhs) \
+ { \
+ return Bool(lhs.underlying() OP rhs); \
+ } \
+ public: \
+ friend bool operator OP (Final const& lhs, T const& rhs) \
+ { \
+ return Final::BOOST_OPAQUE_INTERNAL_NAME(NAME)(lhs, rhs);\
+ } \
+ }; \
+ }; \
+ template <typename Bool, typename T> \
+ struct BOOST_JOIN(hiding_,NAME)<Bool, _self, T > \
+ { \
+ template <typename Final, typename Base> \
+ struct type: Base \
+ { \
+ private:\
+ static Bool BOOST_OPAQUE_INTERNAL_NAME(NAME) (const Final& lhs, const T& rhs); \
+ }; \
+ }; \
+ \
+
+
+#define BOOST_OPAQUE_DCL_META_MIXIN_REL1(OP, NAME) \
     template <typename Bool=bool> \
     struct BOOST_JOIN(using_,NAME) \
     { \
@@ -235,12 +328,16 @@
         { \
         private :\
           template <typename U> \
- static Bool BOOST_JOIN(BOOST_JOIN(using_,NAME),_op) (const Final& lhs, const U& rhs); \
+ static Bool BOOST_OPAQUE_INTERNAL_NAME(NAME) (const Final& lhs, const U& rhs); \
           template <typename U> \
- static Bool BOOST_JOIN(BOOST_JOIN(using_,NAME),_op) (const U& lhs, const Final& rhs); \
+ static Bool BOOST_OPAQUE_INTERNAL_NAME(NAME) (const U& lhs, const Final& rhs); \
         }; \
     }; \
 
+
+#define BOOST_OPAQUE_DCL_META_MIXIN_REL(OP, NAME) \
+ BOOST_OPAQUE_DCL_META_MIXIN_REL2(OP,NAME)
+
 #define BOOST_OPAQUE_USING_REL_OP(Final, Bool, OP) \
         Bool operator OP(const Final& rhs) const { \
             return Bool(Final::underlying(this) OP rhs.underlying());\
@@ -273,7 +370,7 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
-#define BOOST_OPAQUE_DCL_META_MIXIN_BINARY(OP, NAME) \
+#define BOOST_OPAQUE_DCL_META_MIXIN_BINARY1(OP, NAME) \
     struct BOOST_JOIN(using_,NAME) \
     { \
       template <typename Final, typename Base> \
@@ -333,11 +430,14 @@
         struct type: Base \
         { \
         private :\
- static Final BOOST_JOIN(BOOST_JOIN(using_,NAME),_op) (const Final& lhs, const U& rhs); \
- static Final BOOST_JOIN(BOOST_JOIN(using_,NAME),_op) (const U& lhs, const Final& rhs); \
+ static Final BOOST_OPAQUE_INTERNAL_NAME(NAME) (const Final& lhs, const U& rhs); \
+ static Final BOOST_OPAQUE_INTERNAL_NAME(NAME) (const U& lhs, const Final& rhs); \
         }; \
     }; \
 
+#define BOOST_OPAQUE_DCL_META_MIXIN_BINARY(OP, NAME) \
+ BOOST_OPAQUE_DCL_META_MIXIN_BINARY1(OP, NAME)
+
 #define BOOST_OPAQUE_USING_BINARY_OP(Final, OP, NAME) \
     private:\
       static Final BOOST_OPAQUE_INTERNAL_NAME(NAME) (const Final& lhs, const Final& rhs) \
@@ -417,7 +517,7 @@
             { \
             private :\
             template <typename U> \
- static Final BOOST_JOIN(BOOST_JOIN(using_,NAME),_op) (const Final& lhs, const U& rhs); \
+ static Final BOOST_OPAQUE_INTERNAL_NAME(NAME) (const Final& lhs, const U& rhs); \
             }; \
         }; \
 
@@ -549,13 +649,14 @@
           Final& operator OP (const Final& rhs) { \
                Final::underlying(this) OP rhs.underlying();\
                return Final::final(this); \
- } \
+ } \
         }; \
     }; \
     struct BOOST_JOIN(hiding_,NAME) \
     { \
         template <typename Final, typename Base> \
         struct type: Base { \
+ private :\
             Final& operator OP(const Final& rhs); \
         }; \
     };
@@ -658,6 +759,7 @@
     struct hiding_logical_not {
         template <typename Final, typename Base>
         struct type: Base {
+ private :
             Bool operator!() const;
         };
     };
@@ -680,6 +782,7 @@
     struct hiding_logical_and {
         template <typename Final, typename Base>
         struct type: Base {
+ private :
             Bool operator&&(const Final& rhs) const;
         };
     };
@@ -702,6 +805,7 @@
     struct hiding_logical_or {
         template <typename Final, typename Base>
         struct type: Base {
+ private :
             Bool operator||(const Final& rhs) const;
         };
     };
@@ -723,6 +827,7 @@
     struct hiding_unary_plus {
         template <typename Final, typename Base>
         struct type: Base {
+ private :
             Final operator+() const;
         };
     };
@@ -744,6 +849,7 @@
     struct hiding_unary_minus {
         template <typename Final, typename Base>
         struct type: Base {
+ private :\
             Final operator-() const;
         };
     };
@@ -765,6 +871,7 @@
     struct hiding_bitwise_not {
         template <typename Final, typename Base>
         struct type: Base {
+ private :
             Final operator~() const;
         };
     };
@@ -867,6 +974,7 @@
     struct hiding_pre_increment {
         template <typename Final, typename Base>
         struct type: Base {
+ private :
             Final& operator++();
         };
     };
@@ -890,6 +998,7 @@
     struct hiding_pre_decrement {
         template <typename Final, typename Base>
         struct type: Base {
+ private :
             Final& operator--();
         };
     };
@@ -913,6 +1022,7 @@
     struct hiding_post_increment {
         template <typename Final, typename Base>
         struct type: Base {
+ private :
             Final operator++(int);
         };
     };
@@ -936,6 +1046,7 @@
     struct hiding_post_decrement {
         template <typename Final, typename Base>
         struct type: Base {
+ private :
             Final operator--(int);
         };
     };
@@ -1079,7 +1190,6 @@
 
 BOOST_OPAQUE_DCL_META_MIXIN_BINARY_EX(<<, left_shift)
 
-
 //////////////////////////////////////////////////////////////////////////////
 
 #define BOOST_OPAQUE_USING_RIGHT_SHIFT(Final) \

Added: sandbox/opaque/boost/opaque/meta_mixin/placeholder.hpp
==============================================================================
--- (empty file)
+++ sandbox/opaque/boost/opaque/meta_mixin/placeholder.hpp 2011-05-28 15:44:30 EDT (Sat, 28 May 2011)
@@ -0,0 +1,103 @@
+// Boost.TypeErasure library
+//
+// Copyright 2011 Steven Watanabe
+//
+// 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)
+//
+// $Id$
+
+#ifndef BOOST_OPAQUE_PLACEHOLDER_HPP
+#define BOOST_OPAQUE_PLACEHOLDER_HPP
+
+// Base of the file type_erasure/placeholder.hpp even if the purpose is not the same.
+namespace boost {
+namespace opaque {
+
+/** INTERNAL ONLY */
+struct placeholder_base {};
+
+/**
+ * Placeholders are used heavily throughout the library.
+ * Every placeholder must derive from @ref placeholder
+ * using CRTP. The library provides a number of placeholders,
+ * out of the box, but you are welcome to define your own,
+ * if you want more descriptive names. The placeholder
+ * @ref _self is special in that it is used as the default
+ * wherever possible, and that it is used to place the Final template parameter.
+ * There is also the _ut placeholder, which is used to mean the underlying type.
+ *
+ * What exactly is a placeholder? Placeholders act as
+ * a substitute for template parameters in meta-mixins.
+ *
+ * For example, in the following,
+ *
+ * @code
+ template <typename T=_self, typename U=_self>
+ struct lt;
+ template <>
+ struct lt<_self,_self>
+ {
+ template <typename Final, typename Base>
+ struct type: Base
+ {
+ friend bool operator OP (Final const& lhs, Final const& rhs)
+ {
+ return lhs.underlying() OP rhs.underlying();
+ }
+ };
+ };
+ template <typename T>
+ struct lt<T,_self>
+ {
+ template <typename Final, typename Base>
+ struct type: Base
+ {
+ friend bool operator OP (T const& lhs, Final const& rhs)
+ {
+ return lhs OP rhs.underlying();
+ }
+ };
+ };
+ template <typename T>
+ struct lt<_self,T>
+ {
+ template <typename Final, typename Base>
+ struct type: Base
+ {
+ friend bool operator OP (Final const& lhs, T const& rhs)
+ {
+ return lhs.underlying() OP rhs;
+ }
+ };
+ };
+ * @endcode
+ *
+ */
+template<class Derived>
+struct placeholder : placeholder_base {};
+
+struct _a : placeholder<_a> {};
+struct _b : placeholder<_b> {};
+struct _c : placeholder<_c> {};
+struct _d : placeholder<_d> {};
+struct _e : placeholder<_e> {};
+struct _f : placeholder<_f> {};
+struct _g : placeholder<_g> {};
+
+/**
+ * \brief The default placeholder
+ *
+ * @ref _self is the default @ref placeholder used
+ * by meta-mixins. It should be used as a default
+ * by most meta-mixins, so using meta-mixins with no
+ * explicit arguments will "just work" as much as
+ * possible.
+ */
+struct _self : placeholder<_self> {};
+
+}
+}
+
+#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