Boost logo

Boost Users :

From: Pieter Op de Beeck (pieter_at_[hidden])
Date: 2007-07-11 10:33:27


Hi,

I would like to accomplish the following: "bind a functor to a reference and
compose this with another functor". Ultimately I would like to use this
composition with the reference embedded in it.

If I write it like this:

  functor_type h = bind(f, bind(g, ref(b)));

it works alright. However, in my situation the binding of g is done somewhere
else in the program, so have:

  functor_type temp = bind(g, ref(b));
  ...
  functor_type h = bind(f, temp);

Sadly enough this does not appear to work. I don't have a reference to b in h().

I'm sure bind works the way it was intended. I'm more interested in whether you
guys now how to achieve the effect I'm trying to achieve?

Much appreciated,
Pieter.

Some additional context:

using namespace boost;
typedef function<bool ()> functor_type;
struct f { bool operator()(bool b) { return !b; } };
struct g { bool operator()(bool b) { return b; } };
bool b;

The effect I'm trying to achieve:
b = true;
b = h(); // produces !b, so b is now false
b = h(); // produces !b, so b is now true (in the second case above this would
produce false again because there appears to be no reference to b in h())

Pieter Op de Beeck
www.visysglobal.com


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