Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63321 - in sandbox/variadic_templates/boost/composite_storage/pack: . multiple_dispatch
From: cppljevans_at_[hidden]
Date: 2010-06-25 14:59:18


Author: cppljevans
Date: 2010-06-25 14:59:16 EDT (Fri, 25 Jun 2010)
New Revision: 63321
URL: http://svn.boost.org/trac/boost/changeset/63321

Log:
containers & multiple_dispatch code
Added:
   sandbox/variadic_templates/boost/composite_storage/pack/
   sandbox/variadic_templates/boost/composite_storage/pack/container_all_of_aligned.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/pack/container_fwd.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/pack/container_one_of_maybe.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/pack/layout_composite.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/
   sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/apply_unpack.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_switch.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_visitor.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reify_apply.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp (contents, props changed)
   sandbox/variadic_templates/boost/composite_storage/pack/one_of_multiple_dispatch.hpp (contents, props changed)

Added: sandbox/variadic_templates/boost/composite_storage/pack/container_all_of_aligned.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/pack/container_all_of_aligned.hpp 2010-06-25 14:59:16 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,167 @@
+//container template containing all components in template arg list, all of which are aligned.
+#ifndef BOOST_COMPOSITE_STORAGE_CONTAINER_ALL_OF_ALIGNED_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_CONTAINER_ALL_OF_ALIGNED_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/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>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace pack
+{
+ template
+ < class Index0
+ , typename... Components
+ >
+ struct
+container
+ < tags::all_of_aligned
+ , Index0
+ , Components...
+ >
+: layout_composite
+ < tags::all_of_aligned
+ , Index0
+ , Components...
+ >
+{
+ typedef
+ layout_composite
+ < tags::all_of_aligned
+ , Index0
+ , Components...
+ >
+ layout_comp
+ ;
+ typedef
+ typename layout_comp::scanned
+ scanned
+ ;
+ typedef
+ typename layout_comp::index_base
+ index_base
+ ;
+ typedef
+ typename layout_comp::index_undefined
+ index_undefined
+ ;
+ typedef
+ typename layout_comp::index_type
+ index_type
+ ;
+ typedef
+ methods::all_of<scanned,Index0>
+ methods_all
+ ;
+ private:
+ typedef
+ buffers::char_buf
+ < scanned::comp_part::size
+ , scanned::comp_part::align
+ >
+ buffer_type
+ ;
+ buffer_type
+ buffer
+ ;
+ public:
+ container(void)
+ {
+ char*to_buf=buffer.address();
+ methods_all::ctor_default_all(to_buf);
+ }
+ container( container& from)
+ {
+ char *to_buf=buffer.address();
+ char const*fr_buf=from.buffer.address();
+ methods_all::
+ ctor_copy_all
+ ( to_buf
+ , fr_buf
+ );
+ }
+ container( container&& from)
+ {
+ char *to_buf=buffer.address();
+ char *fr_buf=from.buffer.address();
+ methods_all::
+ ctor_copy_all
+ ( to_buf
+ , fr_buf
+ );
+ }
+ container const&
+ operator=(container const& from)
+ {
+ char *to_buf=buffer.address();
+ char const*fr_buf=from.buffer.address();
+ methods_all::
+ assign_all
+ ( to_buf
+ , fr_buf
+ );
+ return *this;
+ }
+ container const&
+ operator=(container&& from)
+ {
+ char *to_buf=buffer.address();
+ buffers::rval_ref_buf fr_buf(from.buffer.address());
+ methods_all::
+ assign_all
+ ( to_buf
+ , fr_buf
+ );
+ return *this;
+ }
+ ~container(void)
+ {
+ scanned::destroy( buffer.address());
+ }
+
+ template
+ < index_type IndexValu
+ >
+ struct result_type
+ {
+ typedef
+ typename mpl::arg<IndexValu-Index0::value+1>::template apply<Components...>::type
+ type
+ ;
+ };
+ template
+ < index_type IndexValu
+ >
+ typename result_type<IndexValu>::type const&
+ project(void)const
+ {
+ mpl::integral_c<index_base,IndexValu> index;
+ return scanned::project(index,buffer.address());
+ }
+ template
+ < index_type IndexValu
+ >
+ typename result_type<IndexValu>::type &
+ project(void)
+ {
+ mpl::integral_c<index_base,IndexValu> index;
+ return scanned::project(index,buffer.address());
+ }
+};
+
+}//exit pack namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+
+#endif

Added: sandbox/variadic_templates/boost/composite_storage/pack/container_fwd.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/pack/container_fwd.hpp 2010-06-25 14:59:16 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,22 @@
+//forward declare all template containers whose components specified with parameter packs.
+#ifndef BOOST_COMPOSITE_STORAGE_PACK_CONTAINER_FWD_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_PWCK_CONTAINER_FWD_HPP_INCLUDED
+#include <boost/composite_storage/tags.hpp>
+namespace boost
+{
+namespace composite_storage
+{
+namespace pack
+{
+ template
+ < class CompositeTag
+ , class Index0
+ , typename... Components
+ >
+ struct
+container
+;
+}//exit pack namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/boost/composite_storage/pack/container_one_of_maybe.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/pack/container_one_of_maybe.hpp 2010-06-25 14:59:16 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,533 @@
+//container template containing, at most, one of components in template arg list.
+#ifndef BOOST_COMPOSITE_STORAGE_CONTAINER_ONE_OF_MAYBE_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_CONTAINER_ONE_OF_MAYBE_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/composite_storage/functor_indexed.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace detail_one_of_maybe
+{
+
+//[functor_indexed_usage
+
+ template
+ < typename Layout
+ , typename FrBuffer
+ >
+struct assign_copy_visitor
+: functor_indexed::layout_visitor<Layout>
+{
+ typedef
+ typename functor_indexed::layout_visitor<Layout>::case_type
+ case_type
+ ;
+ typedef
+ void
+ result_type
+ ;
+ template
+ < case_type CaseValu
+ >
+ result_type operator()( mpl::integral_c<case_type,CaseValu> index) const
+ {
+ Layout::scanned::inject
+ ( index
+ , my_buffer_0
+ , std::move
+ ( *Layout::scanned::project
+ ( index
+ , my_buffer_1
+ )
+ )
+ );
+ }
+
+ assign_copy_visitor
+ ( char* composite_buffer_0
+ , FrBuffer composite_buffer_1
+ )
+ : my_buffer_0(composite_buffer_0)
+ , my_buffer_1(composite_buffer_1)
+ {}
+ private:
+ char*
+ my_buffer_0
+ ;
+ FrBuffer
+ my_buffer_1
+ ;
+};
+
+ template
+ < typename Layout
+ >
+struct equal_visitor
+: functor_indexed::layout_visitor<Layout>
+{
+ typedef
+ typename functor_indexed::layout_visitor<Layout>::case_type
+ case_type
+ ;
+ typedef
+ bool
+ result_type
+ ;
+ template
+ < case_type CaseValu
+ >
+ 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)) ;
+ return result ;
+ }
+
+ equal_visitor
+ ( char const* composite_buffer_0
+ , char const* composite_buffer_1
+ )
+ : my_buffer_0( composite_buffer_0)
+ , my_buffer_1( composite_buffer_1)
+ {}
+ private:
+ char const*
+ my_buffer_0
+ ;
+ char const*
+ my_buffer_1
+ ;
+};
+
+ template
+ < typename Layout
+ >
+struct destroy_visitor
+: functor_indexed::layout_visitor<Layout>
+{
+ typedef
+ typename functor_indexed::layout_visitor<Layout>::cases
+ cases
+ ;
+ typedef
+ typename cases::value_type
+ case_type
+ ;
+ typedef
+ void
+ result_type
+ ;
+ template
+ < case_type CaseValu
+ >
+ result_type operator()( mpl::integral_c<case_type,CaseValu> index) const
+ {
+ Layout::scanned::destroyer(index,my_buffer);
+ }
+
+ destroy_visitor
+ ( char* composite_buffer
+ )
+ : my_buffer(composite_buffer)
+ {}
+ private:
+ char*
+ my_buffer
+ ;
+};
+
+//]functor_indexed_usage
+
+}//exit detail_one_of_maybe namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+
+#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/composite_storage/pack/container_fwd.hpp>
+#include <boost/composite_storage/buffers/char_buf.hpp>
+#include <boost/fusion/support/pair.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace pack
+{
+
+ template
+ < class Index0
+ , typename... Components
+ >
+ struct
+container
+ < tags::one_of_maybe
+ , Index0
+ , Components...
+ >
+: layout_composite
+ < tags::one_of_maybe
+ , Index0
+ , Components...
+ >
+{
+ typedef
+ layout_composite
+ < tags::one_of_maybe
+ , Index0
+ , Components...
+ >
+ layout_comp
+ ;
+ typedef
+ typename layout_comp::scanned
+ scanned
+ ;
+ typedef
+ typename layout_comp::index_base
+ index_base
+ ;
+ typedef
+ typename
+ layout::operators
+ < tags::all_of_aligned
+ >::template push_back
+ < scanned
+ , index_base
+ >::type
+ scanned_index
+ ;
+ typedef
+ typename layout_comp::index_undefined
+ index_undefined
+ ;
+ typedef
+ typename layout_comp::index_type
+ index_type
+ ;
+ private:
+ typedef
+ buffers::char_buf
+ < scanned_index::comp_part::size
+ , scanned_index::comp_part::align
+ >
+ buffer_type
+ ;
+ buffer_type
+ buffer
+ ;
+ void
+ destroy(void)
+ {
+ typedef
+ detail_one_of_maybe::destroy_visitor<layout_comp>
+ visitor_type
+ ;
+ visitor_type
+ buffer_visitor(buffer.address());
+ functor_indexed::apply(buffer_visitor,which());
+ }
+ void
+ assign_copy( container const& from)
+ {
+ typedef
+ detail_one_of_maybe::assign_copy_visitor<layout_comp, char const*>
+ visitor_type
+ ;
+ visitor_type
+ buffer_visitor(buffer.address(), from.buffer.address());
+ functor_indexed::apply(buffer_visitor,from.which());
+ which_put(from.which());
+ }
+ void
+ assign_copy( container&& from)
+ {
+ typedef
+ detail_one_of_maybe::assign_copy_visitor
+ < layout_comp
+ , buffers::rval_ref_buf
+ >
+ visitor_type
+ ;
+ buffers::rval_ref_buf fr_buffer(from.buffer.address());
+ visitor_type
+ buffer_visitor(buffer.address(), fr_buffer);
+ functor_indexed::apply(buffer_visitor,from.which());
+ which_put(from.which());
+ }
+ void
+ which_put(index_base new_which)
+ {
+ typename scanned_index::index_part which_index;
+ index_base& result=scanned_index::project(which_index,buffer.address());
+ result=new_which;
+ }
+ public:
+ index_base
+ which(void)const
+ {
+ typename scanned_index::index_part which_index;
+ index_base const result=scanned_index::project(which_index,buffer.address());
+ return result;
+ }
+ template
+ < index_type IndexValu
+ >
+ static
+ mpl::integral_c< index_type, IndexValu>
+ our_index(void)
+ {
+ return mpl::integral_c< index_type, IndexValu>();
+ }
+ template
+ < index_type IndexValu
+ >
+ mpl::integral_c< index_type, IndexValu>
+ index(void)const
+ {
+ return container::our_index<IndexValu>();
+ }
+ container(void)
+ {
+ which_put(index_undefined::value);
+ }
+ container( container const& from)
+ {
+ assign_copy(from);
+ }
+ container( container&& from)
+ {
+ assign_copy(move(from));
+ }
+ container const&
+ operator=( container const& from)
+ {
+ destroy();
+ assign_copy(from);
+ return *this;
+ }
+ container const&
+ operator=( container&& from)
+ {
+ destroy();
+ assign_copy(std::move(from));
+ return *this;
+ }
+ template
+ < index_type IndexValu
+ , typename Component
+ >
+ container
+ ( mpl::integral_c<index_type,IndexValu>
+ , Component index_component
+ )
+ {
+ mpl::integral_c<index_base,IndexValu> index;
+ scanned::inject( index, buffer.address(), std::forward<Component>(index_component));
+ which_put(IndexValu);
+ }
+ template
+ < index_type IndexValu
+ , typename Component
+ >
+ struct index_component
+ : fusion::pair
+ < mpl::integral_c< index_type, IndexValu>
+ , Component
+ >
+ {
+ typedef
+ fusion::pair
+ < mpl::integral_c< index_type, IndexValu>
+ , Component
+ >
+ super_type
+ ;
+ typedef
+ typename utility::remove_cv_ref
+ < Component
+ >::type
+ comp_type
+ ;
+ index_component(void)
+ : super_type(comp_type())
+ {}
+ index_component(Component a_comp)
+ : super_type(a_comp)
+ {}
+ static
+ index_component
+ _(void)
+ {
+ return index_component();
+ }
+ };
+ template
+ < index_type IndexValu
+ , typename Component
+ >
+ container
+ ( index_component<IndexValu,Component const&> index_component
+ )
+ {
+ mpl::integral_c<index_base,IndexValu> index;
+ scanned::inject
+ ( index
+ , buffer.address()
+ , index_component.second
+ );
+ which_put(IndexValu);
+ }
+ template
+ < index_type IndexValu
+ , typename Component
+ >
+ container
+ ( index_component<IndexValu,Component&&> index_component
+ )
+ {
+ mpl::integral_c<index_base,IndexValu> index;
+ scanned::inject
+ ( index
+ , buffer.address()
+ , std::move(index_component.second)
+ );
+ which_put(IndexValu);
+ }
+ template
+ < index_type IndexValu
+ , typename Component
+ >
+ container const&
+ operator=
+ ( index_component<IndexValu,Component const&> index_component
+ )
+ {
+ destroy();
+ mpl::integral_c<index_base,IndexValu> index;
+ scanned::inject
+ ( index
+ , buffer.address()
+ , index_component.second
+ );
+ which_put(IndexValu);
+ return *this;
+ }
+ template
+ < index_type IndexValu
+ , typename Component
+ >
+ container const&
+ operator=
+ ( index_component<IndexValu,Component&&> index_component
+ )
+ {
+ destroy();
+ mpl::integral_c<index_base,IndexValu> index;
+ scanned::inject
+ ( index
+ , buffer.address()
+ , std::move(index_component.second)
+ );
+ which_put(IndexValu);
+ return *this;
+ }
+
+ ~container(void)
+ {
+ destroy();
+ }
+ template
+ < index_type IndexValu
+ >
+ struct result_type
+ {
+ typedef
+ typename mpl::arg<IndexValu-index_undefined::value+1>
+ ::template apply<special_components::nothing,Components...>::type
+ type
+ ;
+ };
+ template
+ < index_type IndexValu
+ , typename TailConvertible
+ >
+ void
+ inject
+ ( TailConvertible tail_component
+ )
+ {
+ destroy();
+ mpl::integral_c<index_base,IndexValu> index;
+ scanned::inject(index,buffer.address(),std::move(tail_component));
+ which_put(IndexValu);
+ }
+ template
+ < index_type IndexValu
+ >
+ void
+ inject
+ ( void
+ )
+ {
+ destroy();
+ mpl::integral_c<index_base,IndexValu> index;
+ scanned::inject_default(index,buffer.address());
+ which_put(IndexValu);
+ }
+ template
+ < index_type IndexValu
+ >
+ typename result_type<IndexValu>::type const&
+ project(void)const
+ /**@brief
+ * Requires:
+ * IndexValue == which()
+ */
+ {
+ mpl::integral_c<index_base,IndexValu> index;
+ return *scanned::project(index,buffer.address());
+ }
+ template
+ < index_type IndexValu
+ >
+ typename result_type<IndexValu>::type&
+ project(void)
+ /**@brief
+ * Requires:
+ * IndexValue == which()
+ */
+ {
+ mpl::integral_c<index_base,IndexValu> index;
+ return *scanned::project(index,buffer.address());
+ }
+ bool
+ operator==( container const& from)const
+ {
+ if(which() != from.which()) return false;
+ typedef
+ detail_one_of_maybe::equal_visitor<layout_comp>
+ visitor_type
+ ;
+ visitor_type
+ buffer_visitor(buffer.address(), from.buffer.address());
+ bool is_equal=functor_indexed::apply(buffer_visitor,which());
+ return is_equal;
+ }
+};
+
+}//exit pack namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/boost/composite_storage/pack/layout_composite.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/pack/layout_composite.hpp 2010-06-25 14:59:16 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,64 @@
+//operators for calculating the layout of one_of_maybe composite.
+#ifndef BOOST_COMPOSITE_STORAGE_PACK_LAYOUT_COMPOSITE_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_PACK_LAYOUT_COMPOSITE_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/composite_storage/layout/operators_fwd.hpp>
+#include <boost/composite_storage/enum_base.hpp>
+#include <boost/mpl/fold_assoc_pack.hpp>
+#include <boost/mpl/next.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace pack
+{
+ template
+ < class CompositeTag
+ , class Index0
+ , typename... Components
+ >
+struct layout_composite
+{
+ typedef
+ layout::operators<CompositeTag>
+ layout_ops
+ ;
+ typedef
+ typename Index0::value_type
+ index_type
+ ;
+ typedef typename
+ enum_base<Index0>::type
+ index_base
+ ;
+ typedef
+ mpl::integral_c<index_base,index_base(Index0::value)-1>
+ index_undefined
+ ;
+ typedef
+ typename mpl::fold_assoc_pack
+ < mpl::assoc_left
+ , layout_ops::template push_back
+ , typename layout_ops::template layout0<index_undefined>
+ , Components...
+ >::type
+ scanned
+ ;
+ typedef
+ typename mpl::next<typename scanned::index_part>::type
+ index_end
+ ;
+};
+
+}//exit pack
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif
+

Added: sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/apply_unpack.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/apply_unpack.hpp 2010-06-25 14:59:16 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,146 @@
+//
+#ifndef BOOST_COMPOSITE_STORAGE_PACK_MULTIPLE_DISPATCH_APPLY_UNPACK_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_PACK_MULTIPLE_DISPATCH_APPLY_UNPACK_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/package_range_c.hpp>
+#include <boost/type_traits/remove_cv.hpp>
+//#define USE_IS_CALLABLE_WITH_ARGS
+#ifdef USE_IS_CALLABLE_WITH_ARGS
+#include <boost/function_types/is_callable_with_args.hpp>
+#else
+#include <boost/function_types/can_be_called.hpp>
+#endif //#ifdef USE_IS_CALLABLE_WITH_ARGS
+namespace boost
+{
+namespace composite_storage
+{
+namespace pack
+{
+namespace multiple_dispatch
+{
+ template
+ < typename Functor
+ >
+struct functor_result_type
+{
+ typedef
+ typename remove_cv<Functor>::type
+ functor_type
+ ;
+ typedef
+ typename functor_type::result_type
+ type
+ ;
+};
+
+ template
+ < typename Functor
+ , typename... Args
+ >
+ typename functor_result_type<Functor>::type
+apply_ftor_callable_args
+ ( mpl::bool_<true>
+ , Functor& ftor
+ , Args const&... args
+ )
+{
+ return ftor(args...);
+};
+ template
+ < typename Functor
+ , typename... Args
+ >
+ typename functor_result_type<Functor>::type
+apply_ftor_callable_args
+ ( mpl::bool_<false>
+ , Functor& ftor
+ , Args const&... args
+ )
+{
+ std::cout<<"!!!ftor cannot be called with given args.\n";
+ return typename functor_result_type<Functor>::type();
+};
+
+ template
+ < typename Functor
+ , typename... Args
+ >
+ typename functor_result_type<Functor>::type
+apply_ftor_check_args
+ ( Functor& ftor
+ , Args const&... args
+ )
+ /**@brief
+ * If ftor is callable with args..., does so.
+ * If not, then issues error message and returns
+ * default value.
+ */
+{
+ typedef
+ #ifdef USE_IS_CALLABLE_WITH_ARGS
+ typename function_types::is_callable_with_args<Functor(Args const&...)>::type
+ #else
+ typename function_types::can_be_called<Functor(Args const&...)>::type
+ #endif
+ is_ftor_args_callable;
+ return apply_ftor_callable_args
+ ( is_ftor_args_callable()
+ , ftor
+ , args...
+ );
+};
+
+ template
+ < typename Indices
+ >
+struct apply_unpack
+;
+ template
+ < unsigned... Indices
+ //0...Arity-1, where Arity is arity of Functor arg to this->operator()(_,_).
+ >
+struct apply_unpack
+ < mpl::package_c<unsigned, Indices...>
+ >
+{
+ template
+ < typename Functor
+ , typename ArgsPacked
+ >
+ typename functor_result_type<Functor>::type
+ operator()
+ ( Functor& a_functor
+ , ArgsPacked const& a_args
+ )
+ {
+ return
+ #if 1
+ apply_ftor_check_args
+ ( a_functor
+ , a_args.template project<Indices>()...
+ )
+ #else
+ //This branch of #if...#endif can cause compile errors
+ //about "no match for for call to 'SomeFunCall'"
+ //where SomdFunCall is some function name and
+ //parameter type list.
+ a_functor
+ ( a_args.template project<Indices>()...
+ )
+ #endif
+ ;
+ }
+};
+
+}//exit multiple_dispatch namespace
+}//exit pack namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_switch.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_switch.hpp 2010-06-25 14:59:16 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,152 @@
+//
+#ifndef BOOST_COMPOSITE_STORAGE_PACK_MULTIPLE_DISPATCH_REIFIER_SWITCH_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_PACK_MULTIPLE_DISPATCH_REIFIER_SWITCH_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/composite_storage/functor_indexed.hpp>
+#include <boost/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace pack
+{
+namespace multiple_dispatch
+{
+
+ template
+ < typename ReifyApply
+ , typename ArgsConcreteAbstract
+ >
+struct reifier_switch
+;
+ template
+ < typename ReifyApply
+ , typename... HeadConcrete
+ , typename HeadAbstract
+ , typename... TailAbstract
+ >
+struct reifier_switch
+ < ReifyApply
+ , ptrs_target_source
+ < mpl::package
+ < HeadConcrete...
+ >
+ , HeadAbstract
+ , TailAbstract...
+ >
+ >
+ /**@brief
+ * Uses switch statment (in superclass)
+ * to convert HeadAbstract,
+ * a composite_storage<one_of_maybe, _, TailConcrete...>
+ * to one of the TailConcretes, and then call
+ * a ReifyApply with the converted ptrs_target_source.
+ */
+: functor_indexed::layout_visitor<HeadAbstract>
+{
+ typedef
+ typename functor_indexed::layout_visitor<HeadAbstract>::case_type
+ case_type
+ ;
+ typedef
+ typename HeadAbstract::index_type
+ index_type
+ ;
+ ReifyApply const&
+ my_reify
+ ;
+ typedef
+ ptrs_target_source
+ < mpl::package
+ < HeadConcrete...
+ >
+ , HeadAbstract
+ , TailAbstract...
+ >
+ now_tar_src_t
+ ;
+ now_tar_src_t*
+ my_tar_src
+ ;
+ HeadAbstract&
+ my_head_abstract
+ ;
+ reifier_switch
+ ( ReifyApply const& a_reify
+ , now_tar_src_t* 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
+ ;
+ private:
+ template
+ < typename TailConcrete
+ >
+ result_type
+ push_back_concrete
+ ( TailConcrete& a_tail_concrete
+ )const
+ {
+ typedef
+ ptrs_target_source
+ < mpl::package
+ < HeadConcrete...
+ , TailConcrete
+ >
+ , TailAbstract...
+ >
+ next_tar_src_t;
+ next_tar_src_t*
+ next_tar_src_p=replace_source_with_target_ptr(my_tar_src,a_tail_concrete);
+ return my_reify(next_tar_src_p);
+ }
+
+ public:
+ template
+ < case_type CaseValue
+ >
+ result_type
+ operator()
+ ( mpl::integral_c<case_type,CaseValue> index
+ )const
+ {
+ index_type const index_concrete=index_type(CaseValue);
+ auto a_tail_concrete=my_head_abstract.template project<index_concrete>();
+ return this->push_back_concrete(a_tail_concrete);
+ }
+
+ result_type
+ operator()
+ ( void
+ )const
+ {
+ return functor_indexed::apply//calls this->operator()(_)
+ ( *this
+ , my_head_abstract.which()//the CaseValue template arg to this->operator()(_).
+ );
+ }
+};
+
+}//exit namespace multiple_dispatch
+}//exit namespace pack
+
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_visitor.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reifier_visitor.hpp 2010-06-25 14:59:16 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,330 @@
+//
+#ifndef BOOST_COMPOSITE_STORAGE_PACK_MULTIPLE_DISPATCH_REIFIER_VISITOR_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_PACK_MULTIPLE_DISPATCH_REIFIER_VISITOR_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/composite_storage/functor_indexed.hpp>
+#include <boost/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp>
+#include <boost/mpl/pair.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace pack
+{
+namespace multiple_dispatch
+{
+ template
+ < typename ResultType
+ , typename... ConcreteHosts
+ >
+struct reifier_visit_abstract_pack
+;
+ template
+ < typename ResultType
+ >
+struct reifier_visit_abstract_pack
+ < ResultType
+ >
+{
+ void visit(void)
+ //only declared to enable use of
+ // using super_type::visit;
+ //in subclasses.
+ //Should never be called.
+ ;
+};
+ template
+ < typename ResultType
+ , typename ConcreteHead
+ , typename... ConcreteTail
+ >
+struct reifier_visit_abstract_pack
+ < ResultType
+ , ConcreteHead
+ , ConcreteTail...
+ >
+: reifier_visit_abstract_pack
+ < ResultType
+ , ConcreteTail...
+ >
+{
+ typedef
+ reifier_visit_abstract_pack
+ < ResultType
+ , ConcreteTail...
+ >
+ super_type;
+
+ using super_type::visit;
+
+ virtual
+ ResultType
+ visit(ConcreteHead const&)const=0;
+};
+ template
+ < typename ResultType
+ , typename ConcreteHosts
+ >
+struct reifier_visit_abstract_seq
+;
+ template
+ < typename ResultType
+ , typename... ConcreteHosts
+ >
+struct reifier_visit_abstract_seq
+ < ResultType
+ , mpl::package
+ < ConcreteHosts...
+ >
+ >
+ /**@brief
+ * Abstract Visitor class
+ * for abstract Host class whose
+ * concrete subclasses
+ * are ConcreteHosts...
+ */
+: reifier_visit_abstract_pack
+ < ResultType
+ , ConcreteHosts...
+ >
+{
+};
+ template
+ < typename ReifierVisitor
+ , typename ConcretePkg
+ , typename... ConcreteHosts
+ >
+struct reifier_visit_concrete_pack
+;
+ template
+ < typename ReifierVisitor
+ , typename... ConcreteHosts
+ >
+struct reifier_visit_concrete_pack
+ < ReifierVisitor
+ , mpl::package
+ < ConcreteHosts...
+ >
+ >
+: reifier_visit_abstract_seq
+ < typename ReifierVisitor::first
+ , mpl::package
+ < ConcreteHosts...
+ >
+ >
+{
+};
+ template
+ < typename ReifierVisitor
+ , typename ConcretePkg
+ , typename ConcreteHead
+ , typename... ConcreteTail
+ >
+struct reifier_visit_concrete_pack
+ < ReifierVisitor
+ , ConcretePkg
+ , ConcreteHead
+ , ConcreteTail...
+ >
+ /**@brief
+ * Define concrete visit method for ConcreteHead
+ * and then repeat for each ConcreteTail...
+ */
+: reifier_visit_concrete_pack
+ < ReifierVisitor
+ , ConcretePkg
+ , ConcreteTail...
+ >
+{
+ typename ReifierVisitor::first
+ visit(ConcreteHead const&a_host)const
+ {
+ typedef
+ typename ReifierVisitor::second
+ self_derived;
+ self_derived const&
+ self_value=static_cast<self_derived const&>(*this);
+ return self_value.push_back_concrete(a_host);
+ }
+};
+ template
+ < typename ReifierVisitor
+ , typename ConcreteHosts
+ >
+struct reifier_visit_concrete_seq
+;
+ template
+ < typename ReifierVisitor
+ , typename... ConcreteHosts
+ >
+struct reifier_visit_concrete_seq
+ < ReifierVisitor
+ , mpl::package
+ < ConcreteHosts...
+ >
+ >
+ /**@brief
+ * Concrete Visitor class
+ * for abstract Host class whose
+ * concrete subclasses
+ * are ConcreteHosts...
+ */
+: reifier_visit_concrete_pack
+ < ReifierVisitor
+ , mpl::package //store ConcreteHosts... for use in defining abstract visit methods.
+ < ConcreteHosts...
+ >
+ , ConcreteHosts... //used for defining concrete visit methods.
+ >
+{
+};
+ template
+ < typename HostAbsract
+ >
+struct hosts_concrete
+ /**@brief
+ * Metafunction returning mpl::package
+ * of Concrete classes corresponding
+ * to the HostAbstract abstract class.
+ */
+;
+ template
+ < typename ReifyApply
+ , typename ArgsConcreteAbstract
+ >
+struct reifier_visitor
+;
+ template
+ < typename ReifyApply
+ , typename... HeadConcrete
+ , typename HeadAbstract
+ , typename... TailAbstract
+ >
+struct reifier_visitor
+ < ReifyApply
+ , ptrs_target_source //container of pointers.
+ < mpl::package
+ < HeadConcrete...
+ >
+ , HeadAbstract
+ , TailAbstract...
+ >
+ >
+ /**@brief
+ * Uses visitor design pattern (in superclass)
+ * to convert HeadAbstract* to its concrete
+ * subclass pointer, store pointer in a
+ * ptrs_target_source, and then call
+ * a ReifyApply with the modified ptrs_target_source.
+ */
+: reifier_visit_concrete_seq
+ //Uses CRTP:
+ // http://www.informit.com/articles/article.aspx?p=31473&seqNum=3
+ //to implement concrete visitor in the visitor design pattern:
+ // http://www.tml.tkk.fi/~pnr/Tik-76.278/gof/html/Visitor.html
+ //However, instead of the Element term used in Visitor.html,
+ //the term, Host, is used here
+ //( because Visitor::visit(Host) seems more meaningful).
+ //
+ < mpl::pair
+ < typename ReifyApply::result_type
+ , reifier_visitor
+ < ReifyApply
+ , ptrs_target_source
+ < mpl::package
+ < HeadConcrete...
+ >
+ , HeadAbstract
+ , TailAbstract...
+ >
+ >
+ >
+ , typename hosts_concrete
+ < typename remove_cv
+ < HeadAbstract
+ >::type
+ >::type
+ >
+{
+ typedef
+ typename ReifyApply::result_type
+ result_type
+ ;
+ typedef
+ HeadAbstract
+ head_abstract_type
+ ;
+ typedef
+ ptrs_target_source
+ < mpl::package
+ < HeadConcrete...
+ >
+ , HeadAbstract
+ , TailAbstract...
+ >
+ now_tar_src_type
+ ;
+ ReifyApply const&
+ my_reify
+ ;
+ now_tar_src_type*
+ my_tar_src
+ ;
+ 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)
+ {
+ }
+ template
+ < typename TailConcrete
+ >
+ result_type
+ push_back_concrete
+ ( TailConcrete& a_tail_concrete
+ )const
+ {
+ typedef
+ ptrs_target_source
+ < mpl::package
+ < HeadConcrete...
+ , TailConcrete
+ >
+ , TailAbstract...
+ >
+ next_tar_src_t;
+ next_tar_src_t*
+ next_tar_src_p=replace_source_with_target_ptr(my_tar_src,a_tail_concrete);
+ return my_reify(next_tar_src_p);
+ }
+
+ result_type
+ operator()
+ ( 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
+}//exit namespace pack
+
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reify_apply.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/reify_apply.hpp 2010-06-25 14:59:16 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,146 @@
+//
+#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/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp>
+#include <boost/composite_storage/pack/multiple_dispatch/apply_unpack.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace pack
+{
+namespace multiple_dispatch
+{
+ 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.
+ >
+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;
+ Functor& my_functor;
+ reify_apply_impl(Functor& a_functor)
+ : my_functor(a_functor)
+ {}
+ template
+ < typename ArgsConcrete
+ , typename HeadAbstract
+ , typename... TailAbstract
+ >
+ result_type
+ operator()
+ ( ptrs_target_source
+ < ArgsConcrete
+ , HeadAbstract
+ , 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
+ < ArgsConcrete
+ , HeadAbstract
+ , TailAbstract...
+ >
+ ptrs_tar_src_type;
+ Reifier
+ < this_type
+ , ptrs_tar_src_type
+ >
+ reifier
+ ( *this
+ , tar_src_p
+ );
+ return reifier();
+ }
+
+ template
+ < typename... ArgsConcrete
+ >
+ result_type
+ operator()
+ ( ptrs_target_source
+ < mpl::package
+ < ArgsConcrete...
+ >
+ >* tar_src_p
+ )const
+ /**@brief
+ * When there are no more abstract arguments
+ * ( presumably after a number of calls to
+ * the previous member function.
+ * ) apply my_functor to *tar_src_p.
+ */
+ {
+ apply_unpack
+ < typename mpl::package_range_c
+ < unsigned
+ , 0
+ , sizeof...(ArgsConcrete)
+ >::type
+ >
+ uapp;
+ return uapp(my_functor,*tar_src_p);
+ }
+
+};
+
+ template
+ < template
+ < typename ReifyApply
+ , typename ArgsConcreteAbstract
+ >class Reifier
+ , typename Functor
+ , typename... ArgsAbstract
+ >
+ typename Functor::result_type
+reify_apply
+ ( Functor & a_functor
+ , ArgsAbstract const&... 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.
+ */
+{
+ auto
+ ptrs_target_src_v(mk_ptrs_source(a_args_abstract...))
+ //creates container of pointers to a_args_abstract...
+ ;
+ reify_apply_impl<Reifier,Functor> rai(a_functor);
+ return rai(&ptrs_target_src_v);
+}
+
+}//exit namespace multiple_dispatch
+}//exit namespace pack
+
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/pack/multiple_dispatch/replace_source_with_target_ptr.hpp 2010-06-25 14:59:16 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,280 @@
+//ptrs_target_source container and function for convering elements from source to target.
+#ifndef BOOST_COMPOSITE_STORAGE_PACK_MULTIPLE_DISPATCH_REPLACE_SOURCE_WITH_TARGET_PTR_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_PACK_MULTIPLE_DISPATCH_REPLACE_SOURCE_WITH_TARGET_PTR_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/package.hpp>
+#include <boost/mpl/at.hpp>
+#include <boost/type_traits/remove_cv.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace pack
+{
+namespace multiple_dispatch
+{
+ template
+ < typename Types
+ >
+ struct
+void_ptr_array
+ ;
+
+ template
+ < typename Type
+ >
+ typename remove_cv<Type>::type*
+remove_cv_ptr
+ ( Type&
+ value
+ )
+ /**@brief
+ * Removes 'const and volatile' from Type and returns
+ * pointer to value with that type.
+ */
+ {
+ typedef typename remove_cv<Type>::type remove_cv_type;
+ remove_cv_type*rm_cv_ptr=const_cast<remove_cv_type*>(&value);
+ return rm_cv_ptr;
+ }
+
+ template
+ < typename... Types
+ >
+ struct
+void_ptr_array
+ < mpl::package
+ < Types...
+ >
+ >
+ /**@brief
+ * 1) An array of void* to Types...*
+ * 2) A CTOR which takes Types&.. to create these pointers.
+ * 3) A project<I>() function to convert
+ * these pointers back to the Types&... passed to CTOR.
+ */
+ {
+ static
+ unsigned const
+ size
+ =sizeof...(Types)
+ ;
+ typedef
+ void*
+ ptr_type
+ ;
+ ptr_type
+ my_ptrs[size]
+ ;
+ //@CTOR
+ void_ptr_array
+ ( Types&...
+ refs
+ )
+ : my_ptrs
+ { remove_cv_ptr(refs)...
+ }
+ {
+ }
+
+ template
+ < unsigned Index
+ >
+ struct
+ result_type
+ : mpl::at_c
+ < mpl::package<Types...>
+ , Index
+ >
+ {
+ };
+
+ template
+ < unsigned Index
+ >
+ typename result_type<Index>::type&
+ project(void)const
+ {
+ ptr_type vp=my_ptrs[Index];
+ typedef
+ typename result_type<Index>::type
+ arg_type;
+ arg_type*ap=static_cast<arg_type*>(vp);
+ return *ap;
+ }
+ };
+
+ template
+ < typename ArgsTarget //mpl::package of Target types.
+ , typename... ArgsSource //Source types.
+ >
+ struct
+ptrs_target_source
+ //Contains pointers for types
+ //in ArgsTarget and ArgsSource...
+ ;
+
+ template
+ < typename... ArgsSource
+ >
+ struct
+ptrs_target_source
+ < mpl::package
+ < //No Target pointers, yet.
+ >
+ , ArgsSource...
+ >
+ /**@brief
+ * Initial value of a ptrs_target_source, i.e.
+ * before any conversion of ArgsSource pointers
+ * to Target pointers.
+ */
+ : void_ptr_array
+ < mpl::package
+ < ArgsSource...
+ >
+ >
+ {
+ typedef
+ void_ptr_array
+ < mpl::package
+ < ArgsSource...>
+ >
+ super_type
+ ;
+
+ ptrs_target_source
+ ( ArgsSource&...
+ a_args
+ )
+ : super_type(a_args...)
+ {}
+
+ ptrs_target_source
+ ( ptrs_target_source const&
+ a_self
+ )
+ : super_type
+ ( a_self
+ )
+ {}
+ private:
+ ptrs_target_source(void)
+ ;
+ };
+
+ template
+ < typename... ArgsSource
+ >
+ ptrs_target_source
+ < mpl::package
+ < //No target pointers.
+ >
+ , ArgsSource...
+ >
+mk_ptrs_source
+ ( ArgsSource&...
+ a_args
+ )
+ /**Ebrief
+ * Convenience function to create an
+ * "initial" ptrs_target_source, i.e.
+ * one that contains no Target pointers.
+ */
+ {
+ ptrs_target_source
+ < mpl::package
+ <
+ >
+ , ArgsSource...
+ >
+ result_args
+ ( a_args...
+ )
+ ;
+ return result_args;
+ }
+
+ template
+ < typename... ArgsTarget
+ , typename... ArgsSource
+ >
+ struct
+ptrs_target_source
+ < mpl::package
+ < ArgsTarget...
+ >
+ , ArgsSource...
+ >
+ : void_ptr_array
+ < mpl::package
+ < ArgsTarget...
+ , ArgsSource...
+ >
+ >
+ {
+ private:
+ ptrs_target_source(void);
+ ptrs_target_source(ptrs_target_source const&);
+ };
+
+ template
+ < typename... HeadTarget
+ , typename TailTarget
+ , typename HeadSource
+ , typename... TailSource
+ >
+ ptrs_target_source
+ < mpl::package
+ < HeadTarget...
+ , TailTarget
+ >
+ , TailSource...
+ >*
+replace_source_with_target_ptr
+ ( ptrs_target_source
+ < mpl::package
+ < HeadTarget...
+ >
+ , HeadSource
+ , TailSource...
+ >*
+ old_ptrs
+ , TailTarget&
+ tail_target
+ )
+ /**@brief
+ * Replaces HeadSource pointer with TailTarget pointer
+ * and returns pointer to new type of ptrs_target_source
+ * 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;
+ typedef
+ ptrs_target_source
+ < mpl::package
+ < HeadTarget...
+ , TailTarget
+ >
+ , TailSource...
+ >
+ new_p;
+ return static_cast<new_p*>(old_pp);
+ }
+
+}//exit multiple_dispatch namespace
+}//exit pack namespace
+}//exit composite_storage namespace
+}//exit boost namespace
+#endif

Added: sandbox/variadic_templates/boost/composite_storage/pack/one_of_multiple_dispatch.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/boost/composite_storage/pack/one_of_multiple_dispatch.hpp 2010-06-25 14:59:16 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,370 @@
+//
+#ifndef BOOST_COMPOSITE_STORAGE_ONE_OF_MULTIPLE_DISPATCH_HPP_INCLUDED
+#define BOOST_COMPOSITE_STORAGE_ONE_OF_MULTIPLE_DISPATCH_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/assert.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/composite_storage/pack/apply_unpack.hpp>
+
+namespace boost
+{
+namespace composite_storage
+{
+namespace pack
+{
+namespace multiple_dispatch
+{
+//Starting from:
+// [apply_dispatched
+//to:
+// ]apply_dispatched
+//the code (except for the line containing arg_ptrs_buf_value)
+//coped from:
+// /home/evansl/prog_dev/boost-svn/ro/sandbox/variadic_templates
+// /libs/composite_storage/sandbox/apply_dispatched.cpp.~1.23~:148-442.
+
+//[apply_dispatched
+ template
+ < typename Functor
+ , typename ArgsConcrete
+ , typename ArgsAbstract
+ >
+ typename
+ Functor
+ ::result_type
+apply_dispatched
+ ( Functor & a_functor
+ , ArgsConcrete const& a_args_concrete
+ , ArgsAbstract const& a_args_abstract
+ )
+;
+ template
+ < typename Functor
+ , typename ArgsConcrete
+ , typename HeadAbstract
+ , typename ArgsAbstract
+ >
+struct apply_vec
+;
+ template
+ < typename Functor
+ , typename ArgsConcrete
+ , typename HeadAbstract
+ , typename... ArgsAbstract
+ >
+struct apply_vec
+ < Functor
+ , ArgsConcrete
+ , HeadAbstract
+ , arg_ptrs<args_abstract,ArgsAbstract...>
+ >
+{
+ Functor & my_functor;
+ ArgsConcrete const& my_args_concrete;
+ HeadAbstract const& my_head_abstract;
+ typedef arg_ptrs<args_abstract,ArgsAbstract...> args_abstract_t;
+ args_abstract_t const& my_args_abstract;
+ apply_vec
+ ( Functor & a_functor
+ , ArgsConcrete const& a_args_concrete
+ , HeadAbstract const& a_head_abstract
+ , args_abstract_t const& a_args_abstract
+ )
+ : my_functor(a_functor)
+ , my_args_concrete(a_args_concrete)
+ , my_head_abstract(a_head_abstract)
+ , my_args_abstract(a_args_abstract)
+ {}
+ typedef
+ typename Functor::result_type
+ result_type
+ ;
+ typedef
+ typename HeadAbstract::index_base
+ index_base
+ ;
+ template
+ < index_base IndexBaseValue
+ >
+ result_type
+ at_index_compile_time
+ ( void
+ )
+ {
+ BOOST_ASSERT((my_head_abstract.which() == IndexBaseValue));
+ typedef typename HeadAbstract::index_type index_type;
+ index_type const index_value=index_type(IndexBaseValue);
+ typedef typename HeadAbstract::template result_type<index_value>::type head_concrete_t;
+ head_concrete_t const*head_concrete_p=my_head_abstract.template project<index_value>();
+ BOOST_ASSERT((head_concrete_p != (head_concrete_t const*)0));
+ typedef typename args_push<ArgsConcrete,head_concrete_t>::type next_args_concrete_t;
+ next_args_concrete_t next_args_concrete_v(my_args_concrete,head_concrete_p);
+ BOOST_MPL_ASSERT_RELATION(next_args_concrete_t::size,==,ArgsConcrete::size+1);
+ return apply_dispatched
+ ( my_functor
+ , next_args_concrete_v
+ , my_args_abstract
+ );
+ }
+ typedef
+ result_type
+ (apply_vec::*conc_fun)
+ ( void
+ )
+ ;
+ static
+ unsigned const
+ size_conc
+ =HeadAbstract::index_end::value
+ -HeadAbstract::index_undefined::value
+ ;
+ typedef
+ conc_fun
+ vec_fun[size_conc]
+ ;
+ template
+ < index_base... Indices
+ >
+ static
+ vec_fun const&
+ at_indices_fun
+ ( void
+ )
+ {
+ static
+ vec_fun const
+ v=
+ { &apply_vec::at_index_compile_time<Indices>...
+ };
+ return v;
+ }
+ template
+ < typename Indices
+ >
+ struct at_indices_fwd
+ ;
+ template
+ < index_base... Indices
+ >
+ struct at_indices_fwd
+ < mpl::package_c<index_base,Indices...>
+ >
+ {
+ static
+ vec_fun const&
+ _(void)
+ {
+ return apply_vec::at_indices_fun<Indices...>();
+ }
+ };
+ result_type
+ at_index_run_time
+ ( typename HeadAbstract::index_base a_index
+ )
+ {
+ typedef
+ typename mpl::package_range_c
+ < index_base
+ , HeadAbstract::index_undefined::value
+ , HeadAbstract::index_end::value
+ >::type
+ indices;
+ typedef at_indices_fwd<indices> fwd;
+ unsigned const index_unsigned=a_index-HeadAbstract::index_undefined::value;
+ conc_fun at_fun=fwd::_()[index_unsigned];
+ return (this->*at_fun)();
+ }
+
+};
+
+ template
+ < typename Functor
+ , typename ArgsConcrete
+ , typename HeadAbstract
+ , typename... ArgsAbstract
+ >
+ typename
+ Functor
+ ::result_type
+apply_dispatched
+ ( Functor & a_functor
+ , ArgsConcrete const& a_args_concrete
+ , arg_ptrs<args_abstract,HeadAbstract,ArgsAbstract...> const& a_args_abstract
+ )
+{
+ typedef arg_ptrs<args_abstract,ArgsAbstract...> next_args_abstract_t;
+ HeadAbstract const&a_head_abstract=a_args_abstract.get_head();
+ typename HeadAbstract::index_base index_value=a_head_abstract.which();
+ apply_vec
+ < Functor
+ , ArgsConcrete
+ , HeadAbstract
+ , next_args_abstract_t
+ >
+ av
+ ( a_functor
+ , a_args_concrete
+ , a_head_abstract
+ , a_args_abstract.get_tail()
+ );
+ return av.at_index_run_time(index_value);
+}
+
+ template
+ < typename Functor
+ , typename ArgsConcrete
+ >
+ typename
+ Functor
+ ::result_type
+apply_dispatched
+ ( Functor & a_functor
+ , ArgsConcrete const& a_args_concrete
+ , arg_ptrs<args_abstract> const& a_args_abstract
+ )
+{
+ apply_unpack
+ < typename boost::mpl::package_range_c
+ < unsigned
+ , 0
+ , ArgsConcrete::size
+ >::type
+ >
+ uapp
+ ;
+ return uapp(a_functor,a_args_concrete);
+}
+
+ template
+ < typename Functor
+ , typename... ArgsAbstract
+ >
+ typename Functor::result_type
+apply_abstract
+ ( Functor & a_functor
+ , ArgsAbstract const&... a_args_abstract
+ )
+{
+ unsigned const size_args=sizeof...(ArgsAbstract);
+ arg_ptr_type arg_ptrs_buf_concrete[size_args];
+ arg_ptrs<args_concrete> arg_ptrs_concrete(arg_ptrs_buf_concrete);
+ arg_ptr_type arg_ptrs_buf_abstract[size_args];
+ arg_ptrs<args_abstract,ArgsAbstract...> arg_ptrs_abstract(arg_ptrs_buf_abstract, a_args_abstract...);
+ BOOST_MPL_ASSERT_RELATION((arg_ptrs<args_abstract,ArgsAbstract...>::size),==,size_args);
+ return apply_dispatched
+ ( a_functor
+ , arg_ptrs_concrete
+ , arg_ptrs_abstract
+ );
+}
+
+ template
+ < template
+ < typename ReifyApply
+ , typename ArgsConcrete
+ , typename HeadAbstract
+ , typename ArgsAbstract
+ >class Reifier
+ , typename Functor
+ >
+struct reify_apply_impl
+{
+ typedef typename Functor::result_type result_type;
+ typedef reify_apply_impl<Reifier,Functor> this_type;
+ Functor& my_functor;
+ reify_apply_impl(Functor& a_functor)
+ : my_functor(a_functor)
+ {}
+ template
+ < typename ArgsConcrete
+ , typename ArgsAbstract
+ >
+ result_type
+ operator()
+ ( ArgsConcrete const& a_args_concrete
+ , ArgsAbstract const& a_args_abstract
+ )const
+ {
+ Reifier
+ < this_type
+ , ArgsConcrete
+ , typename ArgsAbstract::head_type
+ , typename ArgsAbstract::tail_type
+ >
+ reifier
+ ( *this
+ , a_args_concrete
+ , a_args_abstract.get_head()
+ , a_args_abstract.get_tail()
+ );
+ return reifier();
+ }
+
+ template
+ < typename ArgsConcrete
+ >
+ result_type
+ operator()
+ ( ArgsConcrete const& a_args_concrete
+ , arg_ptrs<args_abstract> const& a_args_abstract
+ )const
+ {
+ apply_unpack
+ < typename boost::mpl::package_range_c
+ < unsigned
+ , 0
+ , ArgsConcrete::size
+ >::type
+ >
+ uapp
+ ;
+ return uapp(my_functor,a_args_concrete);
+ }
+
+};
+
+ template
+ < template
+ < typename ReifyApply
+ , typename ArgsConcrete
+ , typename HeadAbstract
+ , typename ArgsAbstract
+ >class Reifier
+ , typename Functor
+ , typename... ArgsAbstract
+ >
+ typename Functor::result_type
+reify_apply
+ ( Functor & a_functor
+ , ArgsAbstract const&... a_args_abstract
+ )
+{
+ unsigned const size_args=sizeof...(ArgsAbstract);
+
+ arg_ptr_type arg_ptrs_buf_concrete[size_args];
+ typedef arg_ptrs<args_concrete> arg_ptrs_concrete_t;
+ arg_ptrs_concrete_t arg_ptrs_concrete_v(arg_ptrs_buf_concrete);
+
+ arg_ptr_type arg_ptrs_buf_abstract[size_args];
+ typedef arg_ptrs<args_abstract,ArgsAbstract...> arg_ptrs_abstract_t;
+ arg_ptrs_abstract_t arg_ptrs_abstract_v(arg_ptrs_buf_abstract, a_args_abstract...);
+
+ BOOST_MPL_ASSERT_RELATION(arg_ptrs_abstract_t::size,==,size_args);
+
+ reify_apply_impl<Reifier,Functor> ra(a_functor);
+ return ra(arg_ptrs_concrete_v,arg_ptrs_abstract_v);
+}
+//]apply_dispatched
+
+}//exit namespace multiple_dispatch
+}//exit namespace pack
+
+}//exit composite_storage 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