Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69152 - sandbox/variadic_templates/libs/composite_storage/sandbox/pack
From: cppljevans_at_[hidden]
Date: 2011-02-22 12:14:23


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

Log:
*one_of_multiple_dispatch_test.cpp:

Added several more #ifdef REIFIER_VISITOR to highlight differences
between reifier_visitor and reifier_switch. Also add ing prints for
tagged my_id to show no unecessary copies took place:

Text files modified:
   sandbox/variadic_templates/libs/composite_storage/sandbox/pack/composite_storage.leaf.test.cpp | 10 ++++
   sandbox/variadic_templates/libs/composite_storage/sandbox/pack/empty_base.cpp | 9 +++-
   sandbox/variadic_templates/libs/composite_storage/sandbox/pack/one_of_multiple_dispatch.test.cpp | 77 +++++++++++++++++++++++++++++----------
   3 files changed, 73 insertions(+), 23 deletions(-)

Modified: sandbox/variadic_templates/libs/composite_storage/sandbox/pack/composite_storage.leaf.test.cpp
==============================================================================
--- sandbox/variadic_templates/libs/composite_storage/sandbox/pack/composite_storage.leaf.test.cpp (original)
+++ sandbox/variadic_templates/libs/composite_storage/sandbox/pack/composite_storage.leaf.test.cpp 2011-02-22 12:14:22 EST (Tue, 22 Feb 2011)
@@ -19,6 +19,8 @@
 #include "../../utility/curried_offset.hpp"
 
 #include <boost/assert.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits/is_same.hpp>
 
 struct trace_scope
 {
@@ -145,7 +147,11 @@
         tagged_type
         ;
             typedef
- tagged_type::layout_comp::scanned
+ tagged_type::layout_comp
+ layout_comp
+ ;
+ typedef
+ layout_comp::scanned
         layout_scanned
         ;
         ind_out
@@ -153,6 +159,8 @@
           <<":size="<<layout_scanned::comp_part::size<<"\n"
           <<":alignment="<<layout_scanned::comp_part::align<<"\n"
         ;
+ BOOST_MPL_ASSERT((is_same<layout_comp::result_type<index_0>::type,int>));
+ BOOST_MPL_ASSERT((is_same<tagged_type::result_type<index_1>::type,float>));
         {
             trace_scope ts("default CTOR");
               tagged_type

Modified: sandbox/variadic_templates/libs/composite_storage/sandbox/pack/empty_base.cpp
==============================================================================
--- sandbox/variadic_templates/libs/composite_storage/sandbox/pack/empty_base.cpp (original)
+++ sandbox/variadic_templates/libs/composite_storage/sandbox/pack/empty_base.cpp 2011-02-22 12:14:22 EST (Tue, 22 Feb 2011)
@@ -3,7 +3,12 @@
 // in various constructs.
 //Reference:
 // [EBO] http://www.cantrip.org/emptyopt.html
-//
+//Dependencies:
+// [boost.variant]
+// http://www.boost.org/doc/libs/1_44_0/doc/html/variant.html
+// [boost.sandbox.vrtpl.cs]
+// https://svn.boost.org/trac/boost/browser/sandbox/variadic_templates/boost/composite_storage
+//
 #include <boost/composite_storage/pack/container_all_of_aligned.hpp>
 #include <boost/composite_storage/pack/container_one_of_maybe.hpp>
 #include <boost/variant.hpp>
@@ -14,7 +19,7 @@
>
 struct empty_class
 /**@brief
- * This is an empty class, according to:
+ * This is an empty class type, according to [EBO].
  */
 {
         friend

Modified: sandbox/variadic_templates/libs/composite_storage/sandbox/pack/one_of_multiple_dispatch.test.cpp
==============================================================================
--- sandbox/variadic_templates/libs/composite_storage/sandbox/pack/one_of_multiple_dispatch.test.cpp (original)
+++ sandbox/variadic_templates/libs/composite_storage/sandbox/pack/one_of_multiple_dispatch.test.cpp 2011-02-22 12:14:22 EST (Tue, 22 Feb 2011)
@@ -1,4 +1,11 @@
 #include <boost/iostreams/utility/indent_scoped_ostreambuf.hpp>
+//#define MULTIPLE_DISPATCH_DEBUG
+#ifdef MULTIPLE_DISPATCH_DEBUG
+#include <boost/type_traits/is_const.hpp>
+#include <boost/type_traits/is_reference.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/utility/demangled_type_name.hpp>
+#endif
 #include <iostream>
 #include <string>
 #include <boost/mpl/assert.hpp>
@@ -25,15 +32,19 @@
   #else
     #define FUNCTOR_CONSTANCY
   #endif
- #if 0
+ #if 1
     #define ARG_CONSTANCY const
   #else
     #define ARG_CONSTANCY
   #endif
 #define APPLY_UNPACK_USER_CHECKED_ARGS
 #include <boost/composite_storage/pack/multiple_dispatch/reify_apply.hpp>
-#include <boost/composite_storage/pack/multiple_dispatch/reifier_switch.hpp>
-#include <boost/composite_storage/pack/multiple_dispatch/reifier_visitor.hpp>
+//#define REIFIER_VISITOR
+#ifdef REIFIER_VISITOR
+ #include <boost/composite_storage/pack/multiple_dispatch/reifier_visitor.hpp>
+#else
+ #include <boost/composite_storage/pack/multiple_dispatch/reifier_switch.hpp>
+#endif
 #include <boost/composite_storage/pack/container_one_of_maybe.hpp>
 
 namespace boost
@@ -67,12 +78,16 @@
 
 }//exit testing namespace
 
+#ifdef REIFIER_VISITOR
 template <typename ResultType>
 struct hosts_concrete<testing::host_abstract<ResultType> >
- : testing::hosts_indices_concrete< mpl::package_range_c<unsigned, 0,3>::type
- , ResultType>
+ : testing::hosts_indices_concrete
+ < mpl::package_range_c<unsigned, 0,3>::type
+ , ResultType
+ >
 {
 };
+#endif
 
 namespace testing
 {
@@ -101,11 +116,13 @@
     void operator=(host_abstract const&)
     {}
     
+ #ifdef REIFIER_VISITOR
     typedef reifier_visit_abstract_seq< ResultType
       , typename hosts_concrete<host_abstract>::type>
     visitor_abstract;
     
     virtual ResultType accept( visitor_abstract const&)const=0;
+ #endif
 };
 
 template <unsigned I, typename ResultType>
@@ -123,7 +140,7 @@
         v[0]='a';
         v[1]='\0';
     }
-
+ #ifdef REIFIER_VISITOR
     typedef typename host_abstract<ResultType>::visitor_abstract
     visitor_abstract;
     
@@ -131,13 +148,22 @@
     {
         return a_visitor.visit(*this);
     }
+ #endif
 };
 
 template <unsigned I, typename ResultType>
 ind_ostream& operator<<( ind_ostream& sout
   , host_concrete<I,ResultType>const& x)
 {
- sout<<":host_concrete<"<<I<<">(my_id="<<x.my_id<<")";
+ sout<<":host_concrete-yes-const<"<<I<<">(my_id="<<x.my_id<<")";
+ return sout;
+}
+
+template <unsigned I, typename ResultType>
+ind_ostream& operator<<( ind_ostream& sout
+ , host_concrete<I,ResultType>& x)
+{
+ sout<<":host_concrete-non-const<"<<I<<">(my_id="<<x.my_id<<")";
     return sout;
 }
   
@@ -245,6 +271,11 @@
     {
         trace_scope ts("one_of_multiple_dispatch TESTS");
         
+ host_concrete<0> hc0;
+ host_concrete<1> hc1;
+ host_concrete<2> hc2;
+ #ifdef REIFIER_VISITOR
+ #else
         typedef pack::container < tags::one_of_maybe
           , mpl::integral_c<index_numerals,index_0>, host_concrete<0>
           , host_concrete<1>, host_concrete<2> >
@@ -259,14 +290,15 @@
         {
             ind_out<<"v["<<i<<"].which="<<tagged_v[i].which()<<"\n";
         }
- tagged_v[0].inject<index_0>(host_concrete<0>());
- tagged_v[1].inject<index_1>(host_concrete<1>());
- tagged_v[2].inject<index_2>(host_concrete<2>());
+ tagged_v[0].inject<index_0>(hc0);
+ tagged_v[1].inject<index_1>(hc1);
+ tagged_v[2].inject<index_2>(hc2);
         ind_out<<"v after inject:\n";
         for(unsigned i=0; i<arity; ++i)
         {
             ind_out<<"v["<<i<<"].which="<<tagged_v[i].which()<<"\n";
         }
+ #endif
       #define FUNCTOR_T functor3
             typedef
           FUNCTOR_T
@@ -290,11 +322,16 @@
           <<"\n";
       #endif
       #if 1
- //#define REIFIER_VISITOR
         #ifdef REIFIER_VISITOR
- ind_out<<"*** defined(REIFIER_VISITOR)\n";
+ ind_out<<"*** defined(REIFIER_VISITOR)\n";
+ ind_out<<"hc0.my_id="<<hc0.my_id<<"\n";
+ ind_out<<"hc1.my_id="<<hc1.my_id<<"\n";
+ ind_out<<"hc2.my_id="<<hc2.my_id<<"\n";
         #else
- ind_out<<"*** !defined(REIFIER_VISITOR)\n";
+ ind_out<<"*** !defined(REIFIER_VISITOR)\n";
+ ind_out<<"tagged_v[0].my_id="<<tagged_v[0].project<index_0>().my_id<<"\n";
+ ind_out<<"tagged_v[1].my_id="<<tagged_v[1].project<index_1>().my_id<<"\n";
+ ind_out<<"tagged_v[2].my_id="<<tagged_v[2].project<index_2>().my_id<<"\n";
         #endif
         result = pack::multiple_dispatch::reify_apply
           #ifdef REIFIER_VISITOR
@@ -304,27 +341,27 @@
           #endif
>( functor_v
           #ifdef REIFIER_VISITOR
- , static_cast<host_abstract<> ARG_CONSTANCY &>(host_concrete<0>())
- , static_cast<host_abstract<> ARG_CONSTANCY &>(host_concrete<1>())
+ , static_cast<host_abstract<> ARG_CONSTANCY &>(hc0)
+ , static_cast<host_abstract<> ARG_CONSTANCY &>(hc1)
           #else
- , tagged_v[0]
- //, tagged_v[1]
+ , static_cast<tagged_type ARG_CONSTANCY &>(tagged_v[0])
+ , static_cast<tagged_type ARG_CONSTANCY &>(tagged_v[1])
           #endif
           //#define FUNCTOR_INVALID_ARGS
           #if defined(FUNCTOR_INVALID_ARGS)
             //This should fail compilation with error message
             //something about invalid args.
             #ifdef REIFIER_VISITOR
- , static_cast<host_abstract<> ARG_CONSTANCY &>(host_concrete<0>())
+ , static_cast<host_abstract<> ARG_CONSTANCY &>(hc0)
             #else
               , tagged_v[0]
             #endif
           #endif
             );
       #ifdef FUNCTOR_INVALID_ARGS
- ind_out<<"functor_v(v0,V1,v0).result="<<result<<"\n";
+ ind_out<<"functor_v(v0,v1,v0).result="<<result<<"\n";
       #else
- ind_out<<"functor_v(v0,V1).result="<<result<<"\n";
+ ind_out<<"functor_v(v0,v1).result="<<result<<"\n";
       #endif
       #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