[phoenix] Using with Boost.Function.
Can anyone tell me the correct incantation to get the 'Not OK' lines to work? Thx, Rob. #include <boost/function.hpp> #include <boost/phoenix/core.hpp> #include <boost/phoenix/operator.hpp> #include <boost/phoenix/bind/bind_member_variable.hpp> #include <boost/phoenix/bind/bind_function.hpp> #include <boost/function.hpp> #include <list> struct S { int i; }; void f( std::list<S> & l, int i ) { using boost::phoenix::arg_names::_1; using boost::phoenix::arg_names::_2; // OK l.remove_if( bind( & S::i, _1 ) >= i ); *// Not OK.* * boost::function<bool( int, int )> pred = _1 >= _2;* * l.remove_if( bind( pred, _1, i ) );* }
2012/10/22 Robert Jones <robertgbjones@gmail.com>
Can anyone tell me the correct incantation to get the 'Not OK' lines to work?
Thx, Rob.
#include <boost/function.hpp> #include <boost/phoenix/core.hpp> #include <boost/phoenix/operator.hpp> #include <boost/phoenix/bind/bind_member_variable.hpp> #include <boost/phoenix/bind/bind_function.hpp>
+ #include <boost/phoenix/bind/bind_function_object.hpp> #include <boost/function.hpp>
#include <list>
struct S { int i; };
void f( std::list<S> & l, int i ) { using boost::phoenix::arg_names::_1; using boost::phoenix::arg_names::_2;
// OK l.remove_if( bind( & S::i, _1 ) >= i );
*// Not OK.* * boost::function<bool( int, int )> pred = _1 >= _2;*
* l.remove_if( bind( pred, _1, i ) );*
- l.remove_if( bind( pred, _1, i ) ); + l.remove_if( bind( pred, bind( & S::i, _1 ), i ) );
}
Nice try, and thanks for correcting my missing bind invocation, but still no tomato! #include <boost/function.hpp> #include <boost/phoenix/core.hpp> #include <boost/phoenix/operator.hpp> #include <boost/phoenix/bind/bind_member_variable.hpp> #include <boost/phoenix/bind/bind_function.hpp> #include <boost/phoenix/bind/bind_function_object.hpp> #include <boost/function.hpp> #include <list> struct S { int i; }; bool pred_fn( int i, int j ) { return i >= j; } void f( std::list<S> & l, int i ) { using boost::phoenix::arg_names::_1; using boost::phoenix::arg_names::_2; boost::function<bool( int, int )> pred_obj = _1 >= _2; // OK l.remove_if( bind( & S::i, _1 ) >= i ); // OK l.remove_if( bind( pred_fn, bind( & S::i, _1 ), i ) ); // Not OK. l.remove_if( bind( pred_obj, bind( & S::i, _1 ), i ) ); } Results in this error... In file included from /home/rjones/local/gcc-4.6.2/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/list:65:0, from function.cpp:8: /home/rjones/local/gcc-4.6.2/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/list.tcc: In member function ‘void std::list<_Tp, _Alloc>::remove_if(_Predicate) [with _Predicate = std::_Bind<boost::function<bool(int, int)>(boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list2<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::detail::member_variable<int, int S::*> >, 0l>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::argument<1> >, 0l> > >, 2l> >, int)>, _Tp = S, _Alloc = std::allocator<S>]’: function.cpp:28:58: instantiated from here /home/rjones/local/gcc-4.6.2/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/list.tcc:401:6: error: no match for call to ‘(std::_Bind<boost::function<bool(int, int)>(boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list2<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::detail::member_variable<int, int S::*> >, 0l>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::argument<1> >, 0l> > >, 2l> >, int)>) (S&)’ /home/rjones/local/gcc-4.6.2/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1130:11: note: candidates are: /home/rjones/local/gcc-4.6.2/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1201:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) [with _Args = {_Args ...}, _Result = _Result, _Functor = boost::function<bool(int, int)>, _Bound_args = {boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list2<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::detail::member_variable<int, int S::*> >, 0l>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::argument<1> >, 0l> > >, 2l> >, int}] /home/rjones/local/gcc-4.6.2/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1215:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const [with _Args = {_Args ...}, _Result = _Result, _Functor = boost::function<bool(int, int)>, _Bound_args = {boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list2<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::detail::member_variable<int, int S::*> >, 0l>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::argument<1> >, 0l> > >, 2l> >, int}] /home/rjones/local/gcc-4.6.2/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1229:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) volatile [with _Args = {_Args ...}, _Result = _Result, _Functor = boost::function<bool(int, int)>, _Bound_args = {boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list2<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::detail::member_variable<int, int S::*> >, 0l>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::argument<1> >, 0l> > >, 2l> >, int}] /home/rjones/local/gcc-4.6.2/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:1243:2: note: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const volatile [with _Args = {_Args ...}, _Result = _Result, _Functor = boost::function<bool(int, int)>, _Bound_args = {boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list2<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::detail::member_variable<int, int S::*> >, 0l>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::phoenix::argument<1> >, 0l> > >, 2l> >, int}] gmake: *** [function.o] Error 1 Thoughts? Thx, Rob.
2012/11/2 Robert Jones:
Thoughts?
http://liveworkspace.org/code/bd34683a7a5dd82e3e6a33baecd183e2 ? -- Regards, niXman ___________________________________________________ Dual-target(32 & 64-bit) MinGW compilers for 32 and 64-bit Windows: http://sourceforge.net/projects/mingwbuilds/
participants (3)
-
niXman
-
Robert Jones
-
TONGARI