Boost logo

Boost Users :

Subject: Re: [Boost-users] [bind][function] Newbie finds errors, but in Boost or between chair and keyboard?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-01-06 14:11:05


AMDG

Jeroen N.Witmond wrote:
> int main(void)
> {
> boost::function1<bool, int> mything;
>
> mything = boost::bind(doit, 3);
>
> // The statement below results in error:
>
> <snip>
> return mything() ? 0 : 1;
> }
>

boost::function1<bool, int> is a unary function object. You can't call
it with no arguments.
What you meant is probably
boost::function0<bool>.

> // But replacing one_arg_f by its value fails to compile:
> // /usr/include/boost/bind.hpp:413: error: invalid use of void
> // expression
> boost::bind(&anything::operator(), &something, _1, _2,
> boost::bind(&anything::one_arg, &something, _1, 80235))
> (12345, 67890);
>

Nested binds are treated specially. The above tries to invoke:
something(12345, 67890, something.one_arg(12345, 80235));

Try using protect on the inner bind:
boost::protect(boost::bind(&anything::one_arg, &something, _1, 80235)))

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net