Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64378 - sandbox/variadic_templates/boost/mpl
From: cppljevans_at_[hidden]
Date: 2010-07-27 05:29:53


Author: cppljevans
Date: 2010-07-27 05:29:52 EDT (Tue, 27 Jul 2010)
New Revision: 64378
URL: http://svn.boost.org/trac/boost/changeset/64378

Log:
add 'scaffolding' for generalizations of and_ and or_
Added:
   sandbox/variadic_templates/boost/mpl/fold_null_unit.hpp (contents, props changed)
   sandbox/variadic_templates/boost/mpl/null_unit.hpp (contents, props changed)

Added: sandbox/variadic_templates/boost/mpl/fold_null_unit.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/mpl/fold_null_unit.hpp 2010-07-27 05:29:52 EDT (Tue, 27 Jul 2010)
@@ -0,0 +1,180 @@
+#ifndef BOOST_MPL_FOLD_NULL_UNIT_HPP_INCLUDED
+#define BOOST_MPL_FOLD_NULL_UNIT_HPP_INCLUDED
+#include <boost/mpl/null_unit.hpp>
+
+namespace boost
+{
+namespace mpl
+{
+#if 0
+namespace aux
+{
+ template
+ < class Null
+ , class Unit
+ , template<class C>class Converter
+ , typename... T
+ >
+ struct fold_null_unit_impl
+ ;
+ template
+ < class Null
+ , class Unit
+ , template<class C>class Converter
+ >
+ struct fold_null_unit_impl
+ < Null
+ , Unit
+ , Converter
+ >
+ : Unit //If no args, result is Unit.
+ {};
+
+ template
+ < class Null
+ , class Unit
+ , template<class C>class Converter
+ , typename Converted
+ , typename... T
+ >
+ struct fold_null_unit_convert
+ : fold_null_unit_impl
+ < Null
+ , Unit
+ , Converter
+ , T... //If Converted is not Null, ignore it.
+ >
+ {
+ };
+ template
+ < class Null
+ , class Unit
+ , template<class C>class Converter
+ , typename... T
+ >
+ struct fold_null_unit_convert
+ < Null
+ , Unit
+ , Converter
+ , Null //If Converted is Null...
+ , T...
+ >
+ : Null //...result is Null.
+ {
+ };
+
+ template
+ < class Null
+ , class Unit
+ , template<class C>class Converter
+ , typename T0
+ , typename... T
+ >
+ struct fold_null_unit_impl
+ < Null
+ , Unit
+ , Converter
+ , T0
+ , T...
+ >
+ : fold_null_unit_convert
+ < Null
+ , Unit
+ , Converter
+ , typename Converter<T0>::type
+ , T...
+ >
+ {
+ };
+
+}//exit aux namespace
+#endif
+
+ template
+ < class Null
+ , class Unit
+ , template<class C>class Converter
+ , typename... T
+ >
+ struct fold_null_unit
+ /**@brief
+ * Fold of T... where each, for each T,
+ * Converter<T>::type is either Null or Unit,
+ * and where the operation, Op, obeys laws:
+ *
+ * Unit Op T == T.
+ * Null Op T == Null.
+ *
+ * Actually, Op is boost::mpl::null_unit<Null,Unit>::op.
+ *
+ */
+ ;
+
+ template
+ < class Null
+ , class Unit
+ , template<class C>class Converter
+ >
+ struct fold_null_unit
+ < Null
+ , Unit
+ , Converter
+ >
+ : Unit
+ {
+ template
+ < typename... T
+ >
+ struct apply
+ : fold_null_unit
+ < Null
+ , Unit
+ , Converter
+ , T...
+ >
+ {};
+ };
+
+ template
+ < class Null
+ , class Unit
+ , template<class C>class Converter
+ , typename Head
+ , typename... Tail
+ >
+ struct fold_null_unit
+ < Null
+ , Unit
+ , Converter
+ , Head
+ , Tail...
+ >
+ : aux::null_unit_impl
+ < Null
+ , Unit
+ , Converter
+ , typename Converter<Head>::type
+ , fold_null_unit
+ < Null
+ , Unit
+ , Converter
+ , Tail...
+ >
+ >
+ {
+ template
+ < typename... T
+ >
+ struct apply
+ : fold_null_unit
+ < Null
+ , Unit
+ , Converter
+ , T...
+ >
+ {};
+ };
+
+}//exit mpl namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/boost/mpl/null_unit.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/mpl/null_unit.hpp 2010-07-27 05:29:52 EDT (Tue, 27 Jul 2010)
@@ -0,0 +1,90 @@
+#ifndef BOOST_MPL_NULL_UNIT_HPP_INCLUDED
+#define BOOST_MPL_NULL_UNIT_HPP_INCLUDED
+
+namespace boost
+{
+namespace mpl
+{
+ namespace aux
+ {
+ template
+ < class Null
+ , class Unit
+ , template<class C>class Converter
+ , typename T1
+ , typename T2
+ >
+ struct null_unit_impl
+ : Converter<T2>::type
+ //T1 is Unit because, otherwise,
+ //the null_unit_impl specialization
+ //below would be used.
+ {};
+ template
+ < class Null
+ , class Unit
+ , template<class C>class Converter
+ , class T2
+ >
+ struct null_unit_impl
+ < Null
+ , Unit
+ , Converter
+ , Null
+ , T2
+ >
+ : Null //short-circuit the evaluation.
+ {};
+
+ }//exit aux namespace
+
+ template
+ < class Null
+ , class Unit
+ , template<class C>class Converter
+ >
+ struct null_unit
+ /**@brief
+ * Nested template defines binary
+ * metafunction for operation with
+ * 'Null' and 'Unit' elements.
+ * Converter<C>::type converts C to {Null,Unit}.
+ *
+ * For some binary operation, Op,
+ * over domain D:
+ * D Op(D,D)
+ * (i.e. Op is a function taking 2
+ * D's and returning a D.)
+ * the following statements are true:
+ *
+ * 1) D is {Null,Unit}
+ *
+ * 2) For any T in D:
+ *
+ * 2.1) T Op Null == Null
+ * 2.2) Null Op T == Null
+ * 2.3) T Op Unit == T
+ * 2.4) Unit Op T == T
+ *
+ */
+ {
+ template
+ < typename T1
+ , typename T2
+ >
+ struct op
+ : aux::null_unit_impl
+ < Null
+ , Unit
+ , Converter
+ , typename Converter<T1>::type
+ , T2
+ >
+ {
+ };
+ };
+
+
+}//exit mpl namespace
+}//exit boost namespace
+#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