|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-01-30 12:47:08
Alexey Nikitin wrote:
> I try to compile next code:
>
> ===== my_test.cpp =====
> #include <functional>
> #include <boost/bind.hpp>
>
> using namespace std;
> using namespace boost;
>
> struct my_assign_if
> {
> typedef void result_type;
> template<class T, class P>
> void operator()(T& dst, T const& src, P const& to_assign) const { if
> (to_assign()) dst = src; }
> };
>
> int main()
> {
> int a=1, b=0;
> bind(my_assign_if(), ref(a), 0, _1)(bind(less<int>(), cref(b), 1));
> // compiled
> bind(my_assign_if(), ref(a), 0, bind(less<int>(), cref(b), 1))();
> // not compiled
> return 0;
> }
> ====================
> and take next errors: [...]
Nested binds are evaluated. You are trying to call:
my_assign_if()(a, 0, b < 1);
Either change my_assign_if to take a bool argument instead of a predicate,
or wrap the nested bind in protect() (available in boost/bind/protect.hpp)
to prevent its evaluation and pass it unmodified to my_assign_if.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk