Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51383 - trunk/libs/fusion/example/cookbook
From: tschwinger_at_[hidden]
Date: 2009-02-22 01:36:52


Author: t_schwinger
Date: 2009-02-22 01:36:52 EST (Sun, 22 Feb 2009)
New Revision: 51383
URL: http://svn.boost.org/trac/boost/changeset/51383

Log:
adjusts to changes in functional module, also resolves compile problems

Text files modified:
   trunk/libs/fusion/example/cookbook/do_the_bind.cpp | 59 ++++++++++++++++++++++++++++++---------
   1 files changed, 45 insertions(+), 14 deletions(-)

Modified: trunk/libs/fusion/example/cookbook/do_the_bind.cpp
==============================================================================
--- trunk/libs/fusion/example/cookbook/do_the_bind.cpp (original)
+++ trunk/libs/fusion/example/cookbook/do_the_bind.cpp 2009-02-22 01:36:52 EST (Sun, 22 Feb 2009)
@@ -22,23 +22,29 @@
     form.
 ==============================================================================*/
 
+
 #include <boost/fusion/functional/invocation/invoke.hpp>
-#include <boost/fusion/functional/adapter/unfused_generic.hpp>
-#include <boost/fusion/functional/adapter/unfused_rvalue_args.hpp>
+#include <boost/fusion/functional/adapter/unfused.hpp>
 #include <boost/fusion/support/deduce_sequence.hpp>
 
 #include <boost/fusion/sequence/intrinsic/at.hpp>
-#include <boost/fusion/mpl.hpp>
 #include <boost/fusion/sequence/intrinsic/front.hpp>
-#include <boost/fusion/sequence/intrinsic/empty.hpp>
+#include <boost/fusion/sequence/intrinsic/size.hpp>
 #include <boost/fusion/algorithm/transformation/transform.hpp>
 #include <boost/fusion/algorithm/transformation/pop_front.hpp>
+#include <boost/fusion/algorithm/iteration/fold.hpp>
+#include <boost/fusion/view/filter_view.hpp>
+
+#include <boost/functional/forward_adapter.hpp>
+#include <boost/functional/lightweight_forward_adapter.hpp>
 
 #include <boost/type_traits/remove_reference.hpp>
 
 #include <boost/mpl/eval_if.hpp>
 #include <boost/mpl/identity.hpp>
 #include <boost/mpl/int.hpp>
+#include <boost/mpl/max.hpp>
+#include <boost/mpl/next.hpp>
 
 #include <boost/ref.hpp>
 #include <iostream>
@@ -105,6 +111,7 @@
     // returned by bind
     template <class BindArgs> class fused_bound_function
     {
+ // Transform arguments to be held by value
         typedef typename traits::deduce_sequence<BindArgs>::type bound_args;
 
         bound_args fsq_bind_args;
@@ -144,19 +151,40 @@
 
     };
 
+ // Find the number of placeholders in use
+ struct n_placeholders
+ {
+ struct fold_op
+ {
+ template <typename Sig> struct result;
+ template <class S, class A, class B> struct result< S(A &,B &) >
+ : mpl::max<A,B> { };
+ };
+ struct filter_pred
+ {
+ template <class X> struct apply : is_placeholder<X> { };
+ };
+
+ template <typename Seq>
+ struct apply
+ : mpl::next< typename result_of::fold<
+ fusion::filter_view<Seq,filter_pred>, mpl::int_<-1>, fold_op
+ >::type>::type
+ { };
+ };
+
     // Fused implementation of the 'bind' function
     struct fused_binder
     {
         template <class Signature>
         struct result;
 
- template <class BindArgs>
+ template <class BindArgs,
+ int Placeholders = n_placeholders::apply<BindArgs>::value>
         struct result_impl
         {
- // We have to transform the arguments so they are held by-value
- // in the returned function.
- typedef fusion::unfused_generic<
- fused_bound_function<BindArgs> > type;
+ typedef boost::forward_adapter<fusion::unfused<
+ fused_bound_function<BindArgs>,!Placeholders>,Placeholders> type;
         };
 
         template <class Self, class BindArgs>
@@ -168,14 +196,16 @@
         inline typename result_impl< BindArgs >::type
         operator()(BindArgs & bind_args) const
         {
- return typename result< void(BindArgs) >::type(bind_args);
+ return typename result< void(BindArgs) >::type(
+ fusion::unfused< fused_bound_function<BindArgs>,
+ ! n_placeholders::apply<BindArgs>::value >(bind_args) );
         }
     };
 
- // The binder's unfused type. We use unfused_rvalue_args to make that
- // thing more similar to Boost.Bind. Because of that we have to use
+ // The binder's unfused type. We use lightweght_forward_adapter to make
+ // that thing more similar to Boost.Bind. Because of that we have to use
     // Boost.Ref (below in the sample code)
- typedef fusion::unfused_rvalue_args<fused_binder> binder;
+ typedef boost::lightweight_forward_adapter< fusion::unfused<fused_binder> > binder;
 }
 
 // Placeholder globals
@@ -225,10 +255,11 @@
     using boost::ref;
 
     int errors = 0;
+
     errors += !( bind(f)() == 0);
     errors += !( bind(f,"Hi")() == 1);
     errors += !( bind(f,_1_)("there.") == 1);
- errors += !( bind(f,"The answer is",_1_)(value) == 2);
+ errors += !( bind(f,"The answer is",_1_)(12) == 2);
     errors += !( bind(f,_1_,ref(value))("Really?") == 2);
     errors += !( bind(f,_1_,_2_)("Dunno. If there is an answer, it's",value) == 2);
 


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