Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69155 - in sandbox/variadic_templates/boost/composite_storage: . pack pack/multiple_dispatch
From: cppljevans_at_[hidden]
Date: 2011-02-22 12:18:07


Author: cppljevans
Date: 2011-02-22 12:18:03 EST (Tue, 22 Feb 2011)
New Revision: 69155
URL: http://svn.boost.org/trac/boost/changeset/69155

Log:
Mostly, correct some problems (can't remember details) with
multiple_dispatch code in replace_source_with_target_ptr.hpp.

Text files modified:
   sandbox/variadic_templates/boost/composite_storage/pack/container_all_of_aligned.hpp | 7 -
   sandbox/variadic_templates/boost/composite_storage/pack/container_one_of_maybe.hpp | 29 ++++++---
   sandbox/variadic_templates/boost/composite_storage/pack/layout_composite.hpp | 25 +++++++++
   sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_switch.hpp | 5 +
   sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_visitor.hpp | 32 +++++------
   sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reify_apply.hpp | 60 ++++++++++-----------
   sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp | 111 +++++++++++++++++++++++++++++++--------
   sandbox/variadic_templates/boost/composite_storage/special_components.hpp | 8 ++
   8 files changed, 186 insertions(+), 91 deletions(-)

Modified: sandbox/variadic_templates/boost/composite_storage/pack/container_all_of_aligned.hpp
==============================================================================
--- sandbox/variadic_templates/boost/composite_storage/pack/container_all_of_aligned.hpp (original)
+++ sandbox/variadic_templates/boost/composite_storage/pack/container_all_of_aligned.hpp 2011-02-22 12:18:03 EST (Tue, 22 Feb 2011)
@@ -10,7 +10,6 @@
 //====================================================================
 #include <boost/composite_storage/layout/operators_all_of_aligned.hpp>
 #include <boost/composite_storage/pack/layout_composite.hpp>
-#include <boost/mpl/arg.hpp>
 #include <boost/composite_storage/pack/container_fwd.hpp>
 #include <boost/composite_storage/methods/all_of.hpp>
 #include <boost/composite_storage/buffers/layout_buf.hpp>
@@ -126,12 +125,10 @@
       < index_type IndexValu
>
     struct result_type
+ : layout_comp::template result_type<IndexValu>
     {
- typedef
- typename mpl::arg<IndexValu-Index0::value+1>::template apply<Components...>::type
- type
- ;
     };
+
       template
       < index_type IndexValu
>

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 2011-02-22 12:18:03 EST (Tue, 22 Feb 2011)
@@ -43,7 +43,7 @@
           ( index
           , my_buffer_0
           , std::move
- ( *Layout::scanned::project
+ ( Layout::scanned::project
                ( index
                , my_buffer_1
                )
@@ -87,8 +87,8 @@
     result_type operator()( mpl::integral_c<case_type,CaseValu> index) const
     {
         bool result =
- (*Layout::scanned::project(index, my_buffer_0))
- ==(*Layout::scanned::project(index, my_buffer_1)) ;
+ Layout::scanned::project(index, my_buffer_0)
+ ==Layout::scanned::project(index, my_buffer_1) ;
         return result ;
     }
     
@@ -154,7 +154,7 @@
 #include <boost/composite_storage/layout/operators_one_of_maybe.hpp>
 #include <boost/composite_storage/layout/operators_all_of_aligned.hpp>
 #include <boost/composite_storage/pack/layout_composite.hpp>
-#include <boost/mpl/arg.hpp>
+#include <boost/mpl/if.hpp>
 #include <boost/composite_storage/pack/container_fwd.hpp>
 #include <boost/composite_storage/buffers/char_buf.hpp>
 #include <boost/fusion/support/pair.hpp>
@@ -452,13 +452,14 @@
       < index_type IndexValu
>
     struct result_type
+ : mpl::if_c
+ < index_base(IndexValu)==index_undefined::value
+ , special_components::nothing
+ , typename layout_comp::template result_type<IndexValu>::type
+ >
     {
- typedef
- typename mpl::arg<IndexValu-index_undefined::value+1>
- ::template apply<special_components::nothing,Components...>::type
- type
- ;
     };
+
       template
       < index_type IndexValu
       , typename TailConvertible
@@ -497,7 +498,10 @@
        */
     {
         mpl::integral_c<index_base,IndexValu> index;
- return *scanned::project(index,buffer.address());
+#ifdef MULTIPLE_DISPATCH_DEBUG
+ std::cout<<__FILE__<<":project-yes-const<"<<IndexValu<<">()\n";
+#endif
+ return scanned::project(index,buffer.address());
     }
       template
       < index_type IndexValu
@@ -510,7 +514,10 @@
        */
     {
         mpl::integral_c<index_base,IndexValu> index;
- return *scanned::project(index,buffer.address());
+#ifdef MULTIPLE_DISPATCH_DEBUG
+ std::cout<<__FILE__<<":project-not-const<"<<IndexValu<<">()\n";
+#endif
+ return scanned::project(index,buffer.address());
     }
       bool
     operator==( container const& from)const

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 2011-02-22 12:18:03 EST (Tue, 22 Feb 2011)
@@ -12,6 +12,7 @@
 #include <boost/composite_storage/enum_base.hpp>
 #include <boost/mpl/fold_assoc_pack.hpp>
 #include <boost/mpl/next.hpp>
+#include <boost/type_traits/remove_reference.hpp>
 
 namespace boost
 {
@@ -55,6 +56,30 @@
       typename mpl::next<typename scanned::index_part>::type
     index_end
     ;
+ template
+ < index_type IndexValu
+ >
+ struct result_type
+ {
+ typedef
+ mpl::integral_c<index_base,IndexValu>
+ index_value
+ ;
+ typedef
+ decltype
+ ( scanned::project
+ ( index_value()
+ , static_cast<char*>(0)
+ )
+ )
+ ref
+ ;
+ typedef
+ typename
+ remove_reference<ref>::type
+ type
+ ;
+ };
 };
 
 }//exit pack

Modified: sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_switch.hpp
==============================================================================
--- sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_switch.hpp (original)
+++ sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_switch.hpp 2011-02-22 12:18:03 EST (Tue, 22 Feb 2011)
@@ -128,7 +128,10 @@
       )const
     {
         index_type const index_concrete=index_type(CaseValue);
- auto& a_tail_concrete=my_head_abstract.template project<index_concrete>();
+ typedef
+ decltype(my_head_abstract.template project<index_concrete>())
+ tail_type;
+ tail_type a_tail_concrete=my_head_abstract.template project<index_concrete>();
         return this->push_back_concrete(a_tail_concrete);
     }
         

Modified: sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_visitor.hpp
==============================================================================
--- sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_visitor.hpp (original)
+++ sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_visitor.hpp 2011-02-22 12:18:03 EST (Tue, 22 Feb 2011)
@@ -8,7 +8,6 @@
 // This software is provided "as is" without express or implied
 // warranty, and with no claim as to its suitability for any purpose.
 //
-#include <boost/composite_storage/functor_indexed.hpp>
 #include <boost/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp>
 #include <boost/mpl/pair.hpp>
 
@@ -253,13 +252,8 @@
>::type
>
 {
- typedef
- typename ReifyApply::result_type
- result_type
- ;
- typedef
- HeadAbstract
- head_abstract_type
+ ReifyApply const&
+ my_reify
     ;
         typedef
       ptrs_target_source
@@ -271,20 +265,29 @@
>
     now_tar_src_type
     ;
- ReifyApply const&
- my_reify
- ;
       now_tar_src_type*
     my_tar_src
     ;
+ HeadAbstract&
+ my_head_abstract
+ ;
     reifier_visitor
       ( ReifyApply const& a_reify
       , now_tar_src_type* a_ptrs_tar_src
       )
     : my_reify(a_reify)
     , my_tar_src(a_ptrs_tar_src)
+ , my_head_abstract
+ ( my_tar_src->template project
+ < sizeof...(HeadConcrete)
+ >()
+ )
     {
     }
+ typedef
+ typename ReifyApply::result_type
+ result_type
+ ;
       template
       < typename TailConcrete
>
@@ -312,14 +315,9 @@
       ( void
       )const
     {
- head_abstract_type&
- my_head_abstract
- = my_tar_src->template project
- < sizeof...(HeadConcrete)
- >()
- ;
         return my_head_abstract.accept(*this);
     }
+
 };
 
 }//exit namespace multiple_dispatch

Modified: sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reify_apply.hpp
==============================================================================
--- sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reify_apply.hpp (original)
+++ sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reify_apply.hpp 2011-02-22 12:18:03 EST (Tue, 22 Feb 2011)
@@ -1,14 +1,7 @@
 //
 #ifndef BOOST_COMPOSITE_STORAGE_PACK_MULTIPLE_DISPATCH_REIFY_APPLY_HPP_INCLUDED
 #define BOOST_COMPOSITE_STORAGE_PACK_MULTIPLE_DISPATCH_REIFY_APPLY_HPP_INCLUDED
-// (C) Copyright Larry Evans 2010.
-//
-// Permission to copy, use, modify, sell and distribute this software
-// is granted provided this copyright notice appears in all copies.
-// This software is provided "as is" without express or implied
-// warranty, and with no claim as to its suitability for any purpose.
-//====================================================================
-#include <boost/mpl/assert.hpp>
+//#include <boost/mpl/assert.hpp>
 #include <boost/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp>
 #include <boost/composite_storage/pack/multiple_dispatch/apply_unpack.hpp>
 
@@ -22,19 +15,12 @@
 {
   template
   < template
- < typename ReifyApply //this type
- , typename ArgsConcreteAbstract //container concrete followed by abstract args.
- >class Reifier //converter from abstract to concrete arg.
- , typename Functor //Functor on concrete args.
+ < typename ReifyApply
+ , typename ArgsConcreteAbstract
+ >class Reifier
+ , typename Functor
>
 struct reify_apply_impl
- /**@brief
- * A functor, whose operator()(ArgsConcreteAbstract*p_args),
- * recursively applies Reifier to each "abstract" argument in *p_args,
- * accummulating the resulting "concrete" arguments in same p_args,
- * until no more abstract arguments are available, and then
- * applies Functor to the accummulated "concrete" arguments.
- */
 {
     typedef typename Functor::result_type result_type;
     typedef reify_apply_impl<Reifier,Functor> this_type;
@@ -55,12 +41,6 @@
         , TailAbstract...
>* tar_src_p
       )const
- /**@brief
- * Applies conversion, Reifier, to HeadAbstract argument
- * in *tar_src_p, converting it to a concrete argument
- * appended to the end of ArgsConcrete, which replaces
- * the HeadAbstract argument.
- */
     {
             typedef
           ptrs_target_source
@@ -98,6 +78,13 @@
        * ) apply my_functor to *tar_src_p.
        */
     {
+ #ifdef MULTIPLE_DISPATCH_DEBUG
+ std::cout
+ <<"package<ArgsConcrete...>="
+ <<utility::demangled_type_name<mpl::package<ArgsConcrete...> >()
+ <<"\n";
+ return result_type();
+ #else
             apply_unpack
             < typename mpl::package_range_c
               < unsigned
@@ -107,6 +94,7 @@
>
           uapp;
           return uapp(my_functor,*tar_src_p);
+ #endif
     }
 
 };
@@ -122,19 +110,27 @@
   typename Functor::result_type
 reify_apply
   ( Functor & a_functor
- , ArgsAbstract const&... a_args_abstract
+ , ArgsAbstract&... a_args_abstract
   )
   /**@brief
- * Applies a Reifier to each "abstract" argument in
- * a_args_abstract... to produce a container of
- * concrete arguments, which are then passed to a_functor.
+ * Applies Reifier to each argument in a_args_abstract
+ * to produce a list of concrete arguments, which
+ * are then passed to a_functor.
    */
 {
- auto
- ptrs_target_src_v(mk_ptrs_source(a_args_abstract...))
- //creates container of pointers to a_args_abstract...
+ typename ptrs_target0_source
+ < ArgsAbstract...
+ >::type
+ ptrs_target_src_v(a_args_abstract...)
+ //creates container of void pointers to a_args_abstract...
     ;
     reify_apply_impl<Reifier,Functor> rai(a_functor);
+ #ifdef MULTIPLE_DISPATCH_DEBUG
+ std::cout
+ <<"reify_apply::ptrs_target_src_v="
+ <<utility::demangled_type_name(ptrs_target_src_v)
+ <<"\n";
+ #endif
     return rai(&ptrs_target_src_v);
 }
 

Modified: sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp
==============================================================================
--- sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp (original)
+++ sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp 2011-02-22 12:18:03 EST (Tue, 22 Feb 2011)
@@ -74,22 +74,57 @@
         ptr_type
       my_ptrs[size]
         ;
+ #define VOID_PTR_ARRAY_NO_INIT_LIST defined(__clang__)
+ #if VOID_PTR_ARRAY_NO_INIT_LIST
+ template
+ < typename... Refs
+ >
+ void
+ assign_ptrs
+ ( Refs&...refs
+ )
+ ;
+ template
+ < typename RefHead
+ , typename... RefsTail
+ >
+ void
+ assign_ptrs
+ ( RefHead& ref_head
+ , RefsTail&... refs_tail
+ )
+ {
+ my_ptrs[sizeof...(Types)-sizeof...(RefsTail)-1]=remove_cv_ptr(ref_head);
+ assign_ptrs(refs_tail...);
+ }
+ void
+ assign_ptrs()
+ {
+ }
+ #endif
         //@CTOR
       void_ptr_array
         ( Types&...
           refs
         )
+ #if VOID_PTR_ARRAY_NO_INIT_LIST
+ #else
+ //g++
         : my_ptrs
- { remove_cv_ptr(refs)...
- }
+ ( { remove_cv_ptr(refs)... }
+ )
+ #endif
         {
+ #if VOID_PTR_ARRAY_NO_INIT_LIST
+ assign_ptrs(refs...);
+ #endif
         }
-
+
         template
         < unsigned Index
>
         struct
- result_type
+ result_type
         : mpl::at_c
           < mpl::package<Types...>
           , Index
@@ -100,13 +135,27 @@
         template
         < unsigned Index
>
- typename result_type<Index>::type&
+ typename result_type
+ < Index
+ >::type&
       project(void)const
         {
             ptr_type vp=my_ptrs[Index];
                 typedef
               typename result_type<Index>::type
             arg_type;
+ #ifdef MULTIPLE_DISPATCH_DEBUG
+ result_type<Index>();
+ std::cout
+ <<"project.\n"
+ <<":Index="
+ <<Index
+ <<"\n"
+ <<":arg_type="
+ <<utility::demangled_type_name<arg_type>()
+ <<"\n"
+ ;
+ #endif
             arg_type*ap=static_cast<arg_type*>(vp);
             return *ap;
         }
@@ -204,15 +253,31 @@
         {}
   };
 
+
   template
   < typename... ArgsSource
>
- ptrs_target_source
- < mpl::package
- < //No target pointers.
- >
- , ArgsSource...
+struct ptrs_target0_source
+ /**@brief
+ * Metafunction returning ptrs_target_source
+ * with empty targets
+ */
+{
+ typedef
+ ptrs_target_source
+ < mpl::package<>
+ , ArgsSource...
+ >
+ type
+ ;
+};
+
+ template
+ < typename... ArgsSource
>
+ typename ptrs_target0_source
+ < ArgsSource...
+ >::type
 mk_ptrs_source
   ( ArgsSource&...
     a_args
@@ -236,11 +301,9 @@
      return result_args;
   }
 
- ptrs_target_source
- < mpl::package
- < //No target pointers.
- >
- >
+ typename ptrs_target0_source
+ <
+ >::type
 mk_ptrs_source
   ( void
   )
@@ -309,15 +372,17 @@
     tail_target
   )
   /**@brief
- * Replaces HeadSource pointer with TailTarget pointer
- * and returns pointer to new type of ptrs_target_source
- * reflecting that replacement.
+ * Replaces the:
+ * HeadSource*
+ * value within old_ptrs with a:
+ * TailTarget*
+ * and coerce old_ptr to a pointer to a new
+ * type reflecting that replacement.
    */
   {
       std::size_t const index=sizeof...(HeadTarget);
- typedef typename remove_cv<TailTarget>::type target_rm_cv;
- old_ptrs->my_ptrs[index]=const_cast<target_rm_cv*>(&tail_target);
- void*old_pp=old_ptrs;
+ old_ptrs->my_ptrs[index]=remove_cv_ptr(tail_target);//replacement
+ void*old_pp=old_ptrs;//begin coercion of old_ptrs
           typedef
         ptrs_target_source
         < mpl::package
@@ -326,8 +391,8 @@
>
         , TailSource...
>
- new_p;
- return static_cast<new_p*>(old_pp);
+ new_p;//new type reflecting replacement.
+ return static_cast<new_p*>(old_pp);//returned completed coercion of old_ptrs
   }
     
 }//exit multiple_dispatch namespace

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 2011-02-22 12:18:03 EST (Tue, 22 Feb 2011)
@@ -27,12 +27,16 @@
     template<special_id Id>
     struct special_type
     {
+ typedef
+ special_type
+ type
+ ;
             static
- special_type*
+ special_type&
         _(void)
         {
             static special_type a;
- return &a;
+ return a;
         }
         special_type(void)
         {}


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