Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78405 - in sandbox/variadic_templates/boost/composite_storage: . pack
From: cppljevans_at_[hidden]
Date: 2012-05-10 11:32:11


Author: cppljevans
Date: 2012-05-10 11:32:10 EDT (Thu, 10 May 2012)
New Revision: 78405
URL: http://svn.boost.org/trac/boost/changeset/78405

Log:
Added dispatch_indexed template to functor_indexed.hpp
which allowed replacement of reifier_{switch,funvec}
in pack/multiple_dispatch with new reifier_indexed.hpp.

Changes in other files I don't think were more than just
cosmetic.

Text files modified:
   sandbox/variadic_templates/boost/composite_storage/functor_indexed.hpp | 244 ++++++++++++++++++++++-----------------
   sandbox/variadic_templates/boost/composite_storage/pack/container_one_of_maybe.hpp | 33 +++--
   sandbox/variadic_templates/boost/composite_storage/pack/indexed_ctor_args_all_of_aligned.hpp | 4
   sandbox/variadic_templates/boost/composite_storage/pack/layout_composite.hpp | 4
   sandbox/variadic_templates/boost/composite_storage/special_components.hpp | 8
   5 files changed, 168 insertions(+), 125 deletions(-)

Modified: sandbox/variadic_templates/boost/composite_storage/functor_indexed.hpp
==============================================================================
--- sandbox/variadic_templates/boost/composite_storage/functor_indexed.hpp (original)
+++ sandbox/variadic_templates/boost/composite_storage/functor_indexed.hpp 2012-05-10 11:32:10 EDT (Thu, 10 May 2012)
@@ -17,8 +17,9 @@
   #include <boost/control/switch.hpp>
   #include <boost/control/case.hpp>
 //]switch #includes
-#include <boost/assert.hpp>
-#include <boost/type_traits/remove_cv.hpp>
+#include <boost/mpl/range_c.hpp>
+#include <boost/mpl/package_range_c.hpp>
+#include <boost/mpl/front.hpp>
 
 namespace boost
 {
@@ -39,158 +40,185 @@
 // typedef IndexFunctor::cases::value_type IndexType;
 // IndexType IndexValu;
 //
-// the case_c argument above is called
-// "case argument"
-// below.
-//
 {
 
-//The following modified from:
-// http://svn.boost.org/svn/boost/sandbox/switch/libs/switch/example/apply_visitor.cpp
-//As it was on 2009-12-03.1238 CST
-//
-//The comments here starting with //[functor_indexed
-//correspond to the comments in apply_visitor.cpp starting with //[apply_visitor
-//
-//[functor_indexed_implementation
-//
-// bring switch_ and case_ into scope.
 using namespace boost::control;
 
-// One of the cases should always be selected. If the
-// the default is executed it must be an error.
-template<class R>
-struct never_called
-{
- template<class Int>
- R operator()(Int)
- {
- BOOST_ASSERT(!"this function should never be called.");
- }
-};
-
   template
- < class Visitor
- //functor with signature (case_c,Component) -> Visitor::result_type
- //where:
- // case_c (see below).
- // component is some component of Variant.
- //
- , class Variant
- // Abstractly, a "dependent index pair", IOW, like std::pair<Key,Value>,
- // except the type of Value depends on the value of Key part of the pair.
- // Also Key is of type like case_c below.
- //
- // The possible values of Value are called the Components of Variant.
- >
-struct visitor_variant
-/**@brief
- * Adapts the Visitor functor to the
- * Index Functor Interface.
- */
+ < typename IndexFunctor //an Index Functor (see above).
+ , typename Indexes
+ >
+ struct
+dispatch_indexes
+;
+ template
+ < typename IndexFunctor
+ , typename IndexType
+ , IndexType Start
+ , IndexType Finish
+ >
+ struct
+dispatch_indexes
+ < IndexFunctor
+ , mpl::range_c< IndexType, Start, Finish>
+ >
 {
- public:
- typedef
- typename Visitor::cases
- cases
- ;
         typedef
- typename cases::value_type
- case_type
+ typename IndexFunctor::result_type
+ result_type
     ;
         typedef
- typename Visitor::result_type
- result_type
+ mpl::range_c< IndexType, Start, Finish>
+ indexes
     ;
- visitor_variant( Visitor& visitor, Variant& variant)
- : visitor_(visitor)
- , variant_(variant)
- {}
- template<case_type CaseValu>
+ static
       result_type
- operator()
- ( mpl::integral_c<case_type,CaseValu> case_c
+ apply
+ ( IndexFunctor& index_functor
+ , IndexType a_index
       )
- {
- typedef
- typename Variant::index_type
- index_type
- ;
- return
- visitor_
- ( case_c //pass index to visitor
- , *(variant_.template project<index_type(CaseValu)>())//pass component to visitor
- );
- }
- private:
- Visitor& visitor_;
- Variant& variant_;
+ {
+ return
+ switch_<typename IndexFunctor::result_type>
+ ( a_index
+ , case_<typename IndexFunctor::indexes>(index_functor)
+ );
+ }
 };
 
   template
- < class IndexFunctor //an Index Functor (see above).
+ < typename IndexFunctor
+ , typename IndexType
+ , IndexType... Indexes
>
   struct
-apply_static
+dispatch_indexes
+ < IndexFunctor
+ , mpl::package_c
+ < IndexType
+ , Indexes...
+ >
+ >
 {
         typedef
- typename remove_cv<IndexFunctor>::type
- index_functor
- ;
- typedef
- typename index_functor::result_type
+ typename IndexFunctor::result_type
     result_type
     ;
- typedef
- typename index_functor::cases
- cases
- ;
+ template<IndexType IndexVal>
+ struct fun_index
+ {
+ static
+ result_type
+ apply(IndexFunctor& f)
+ {
+ mpl::integral_c<IndexType, IndexVal> arg;
+ return f(arg);
+ }
+ };
         static
       result_type
- _
+ apply
       ( IndexFunctor& index_functor
- , typename index_functor::cases::value_type a_case
+ , IndexType a_index
       )
- {
- never_called<result_type>
- default_
- ;
- return
- switch_<result_type>(a_case, case_<cases>(index_functor), default_);
- }
+ {
+ static
+ unsigned const
+ vec_size
+ = sizeof...(Indexes)
+ ;
+ typedef
+ result_type
+ (*
+ fun_type
+ )(IndexFunctor&)
+ ;
+ static
+ fun_type constexpr
+ vec_funs[vec_size]=
+ { &fun_index<Indexes>::apply...
+ };
+ typedef typename
+ mpl::front
+ < mpl::package_c
+ < IndexType
+ , Indexes...
+ >
+ >::type
+ start_t
+ ;
+ int const
+ vec_offset=a_index-start_t::value;
+ return vec_funs[vec_offset](index_functor);
+ }
 };
 
   template
- < class IndexFunctor //an Index Functor (see above).
+ < typename IndexFunctor //an Index Functor (see above).
>
   typename IndexFunctor::result_type
 apply
   ( IndexFunctor& index_functor
- , typename IndexFunctor::cases::value_type a_case
+ , typename IndexFunctor::indexes::value_type a_index
   )
 {
- return apply_static<IndexFunctor>::_( index_functor, a_case);
+ typedef
+ dispatch_indexes
+ < IndexFunctor
+ , typename IndexFunctor::indexes
+ >
+ dispatcher;
+ return
+ dispatcher::
+ apply
+ ( index_functor
+ , a_index
+ );
 };
 
 //]functor_indexed_implementation
 
   template
   < typename Layout
- , typename Case0=typename Layout::index_undefined
+ , typename Index0=typename Layout::index_undefined
+ //***CAUTION***
+ // If Layout is a one_of_maybe container type
+ // and Index0 has the default value,
+ // then calling Layout::project<Index0::value>()
+ // gives a special_type<nothing_id> value.
+ // (see ./special_components.hpp).
+ , template
+ < typename IndexType
+ , IndexType Start
+ , IndexType Finish
+ >class
+ Container=mpl::
+ #define LAYOUT_DOMAIN_CONTAINER_PACK
+ #ifdef LAYOUT_DOMAIN_CONTAINER_PACK
+ package_range_c
+ #else
+ range_c
+ #endif
>
-struct layout_visitor
+struct layout_domain
+ /**@brief
+ * Define domain of a composite, where 'domain'
+ * means the possible values of the indexes used
+ * to retrieve some component of the composite.
+ */
 {
         typedef
- typename Case0::value_type
- case_type
+ typename Index0::value_type
+ index_type
     ;
         typedef
- mpl::range_c
- < case_type
- , Case0::value
+ typename
+ Container
+ < index_type
+ , Index0::value
       , Layout::index_end::value
- >
- cases
+ >::type
+ indexes
     ;
 };
 

Modified: sandbox/variadic_templates/boost/composite_storage/pack/container_one_of_maybe.hpp
==============================================================================
--- sandbox/variadic_templates/boost/composite_storage/pack/container_one_of_maybe.hpp (original)
+++ sandbox/variadic_templates/boost/composite_storage/pack/container_one_of_maybe.hpp 2012-05-10 11:32:10 EDT (Thu, 10 May 2012)
@@ -25,10 +25,10 @@
   , typename FrBuffer
>
 struct assign_copy_visitor
-: functor_indexed::layout_visitor<Layout>
+: functor_indexed::layout_domain<Layout>
 {
         typedef
- typename functor_indexed::layout_visitor<Layout>::case_type
+ typename functor_indexed::layout_domain<Layout>::index_type
     case_type
     ;
         typedef
@@ -72,10 +72,10 @@
   < typename Layout
>
 struct equal_visitor
-: functor_indexed::layout_visitor<Layout>
+: functor_indexed::layout_domain<Layout>
 {
         typedef
- typename functor_indexed::layout_visitor<Layout>::case_type
+ typename functor_indexed::layout_domain<Layout>::index_type
     case_type
     ;
         typedef
@@ -113,14 +113,10 @@
   < typename Layout
>
 struct destroy_visitor
-: functor_indexed::layout_visitor<Layout>
+: functor_indexed::layout_domain<Layout>
 {
         typedef
- typename functor_indexed::layout_visitor<Layout>::cases
- cases
- ;
- typedef
- typename cases::value_type
+ typename functor_indexed::layout_domain<Layout>::index_type
     case_type
     ;
         typedef
@@ -327,11 +323,22 @@
     }
       template
       < index_type IndexValu
+ >
+ container
+ ( mpl::integral_c<index_type,IndexValu>
+ )
+ {
+ mpl::integral_c<index_base,IndexValu> index;
+ scanned::inject_default( index, buffer.address());
+ which_put(IndexValu);
+ }
+ template
+ < index_type IndexValu
       , typename Component
>
     container
       ( mpl::integral_c<index_type,IndexValu>
- , Component a_component
+ , Component&& a_component
       )
     {
         mpl::integral_c<index_base,IndexValu> index;
@@ -429,7 +436,7 @@
     {
         mpl::integral_c<index_base,IndexValu> index;
 #ifdef MULTIPLE_DISPATCH_DEBUG
- std::cout<<__FILE__<<":project-yes-const<"<<IndexValu<<">()\n";
+ std::cout<<__FILE__<<":"<<__LINE__<<":project-yes-const<"<<IndexValu<<">()\n";
 #endif
         return scanned::project(index,buffer.address());
     }
@@ -445,7 +452,7 @@
     {
         mpl::integral_c<index_base,IndexValu> index;
 #ifdef MULTIPLE_DISPATCH_DEBUG
- std::cout<<__FILE__<<":project-not-const<"<<IndexValu<<">()\n";
+ std::cout<<__FILE__<<":"<<__LINE__<<":project-not-const<"<<IndexValu<<">()\n";
 #endif
         return scanned::project(index,buffer.address());
     }

Modified: sandbox/variadic_templates/boost/composite_storage/pack/indexed_ctor_args_all_of_aligned.hpp
==============================================================================
--- sandbox/variadic_templates/boost/composite_storage/pack/indexed_ctor_args_all_of_aligned.hpp (original)
+++ sandbox/variadic_templates/boost/composite_storage/pack/indexed_ctor_args_all_of_aligned.hpp 2012-05-10 11:32:10 EDT (Thu, 10 May 2012)
@@ -101,7 +101,7 @@
>
     : index_component<index_type,Keys,CtorTypes>...
     /**brief
- * A functor for injecting every component in to
+ * A functor for injecting every component into
      * the composite when used with mpl::for_each.
      */
     {
@@ -196,7 +196,7 @@
           ( mpl::integral_c<index_base,IndexValue> a_index
           )const
           /**@brief
- * If the arg with IndexValue was pass to CTOR,
+ * If the arg with IndexValue was passed to CTOR,
            * inject that into my_buffer at IndexValue;
            * Otherwise:
            * inject the default value into my_buffer at IndexValue.

Modified: sandbox/variadic_templates/boost/composite_storage/pack/layout_composite.hpp
==============================================================================
--- sandbox/variadic_templates/boost/composite_storage/pack/layout_composite.hpp (original)
+++ sandbox/variadic_templates/boost/composite_storage/pack/layout_composite.hpp 2012-05-10 11:32:10 EDT (Thu, 10 May 2012)
@@ -44,6 +44,10 @@
     index_undefined
     ;
         typedef
+ mpl::integral_c<index_base,index_base(Index0::value)>
+ index_beg
+ ;
+ typedef
       typename mpl::fold_assoc_pack
       < mpl::assoc_left
       , layout_ops::template push_back

Modified: sandbox/variadic_templates/boost/composite_storage/special_components.hpp
==============================================================================
--- sandbox/variadic_templates/boost/composite_storage/special_components.hpp (original)
+++ sandbox/variadic_templates/boost/composite_storage/special_components.hpp 2012-05-10 11:32:10 EDT (Thu, 10 May 2012)
@@ -21,8 +21,12 @@
     //
     // http://en.wikipedia.org/wiki/Monoidal_category
     //
- { nothing_id //signifies error, something like haskell's Nothing.
- , empty_id //signifies empty class.
+ { nothing_id
+ //signifies something like haskell's Nothing,
+ //or a variant with 0 components.
+ , empty_id
+ //signifies empty tuple,
+ //or a tuple with 0 components.
     };
     template<special_id Id>
     struct special_type


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