Boost logo

Boost Users :

From: khuroth (dansilva_at_[hidden])
Date: 2002-08-27 09:31:04


Yeah, I'm not sure why I used _1 in the example, but ultimately my
goal is to delay the call to the DoSomething method of Controller.

something like this would feel kind of natural:

boost::function0<Controller&> delayed_controller = (this ->*
&View::GetController);

bind(_1 ->* &Controller::DoSomething, delayed_controller );

but delayed_controller is a function instead of a Controller pointer
and its return type isn't a Controller pointer either, it's a
Controller reference.

--- In Boost-Users_at_y..., Jaakko Jarvi <jajarvi_at_c...> wrote:
> I'm not exactly sure what you are trying to do, but here's some
> explanation on bind and ->*
>
> First, The dot operator cannot be overloaded, so you do this:
>
> (_1 ->* &A::GetController).DoSomething
>
> // DoSomething is not defined for (_1 ->* &A::GetController)
>
>
>
> The semantics of ->* in general is rather tricky, and the Lambda
Library
> mimics that:
>
> Here's a snippet of the LL docs:
>
> For a built-in call like this, the result is kind of a delayed
> member function call. Such an expression must be followed by a
function
> argument list, with which the delayed member function call is
performed.
> For example:
>
> struct B { int foo(int); };
> B* b = new B();
> ...
> (b ->* &B::foo) // returns a delayed call to b->foo
> // a function argument list must follow
> (b ->* &B::foo)(1) // ok, calls b->foo(1)
>
> (_1 ->* &B::foo)(b); // returns a delayed call to b->foo,
> // no effect as such
> (_1 ->* &B::foo)(b)(1); // calls b->foo(1)
>
>
> The LL can figure out the return type when binding a pointer to
member
> function so you do no have to say bind<Controller&>, just bind is
enugh.
>
> If you just try to bind a member function call, leaving the object
open,
> you would write:
>
> bind(&View::GetController, _1);
>
> Could be called as:
>
> View w;
> bind(&View::GetController, _1)(v);
>
> Cheers, Jaakko
>
> On Tue, 27 Aug 2002, khuroth wrote:
>
> > whoops, sorry about the typos.  any A:: here is really View::
> >
> > --- In Boost-Users_at_y..., "khuroth" <dansilva_at_l...> wrote:
> > > I have a View class that has some widgets, and a Controller
class
> > > that controls the view, so the View class has a GetController()
> > > member function that returns a reference to its controller.
> > > When the View's constructor is called, GetController() would
> > return
> > > a bad ref, but it would return a valid reference by the time a
> > > button is clicked... so what I'm trying to do is, inside the
View
> > > constructor:
> > >
> > > my_button.on_click = bind( (_1 ->*
&A::GetController).DoSomething
> > (),
> > > this );
> > >
> > > but that obviously doesn't work... I'm even having trouble just
> > > saving the first part:
> > >
> > > my_button.on_click = bind<Controller&>(_1 ->*
&A::GetController,
> > > this);
> > >
> > > also doesn't work...
> > > I tried defining the on_click member of the button as a
> > > boost::function<void> or a boost::function0<void> in the first
> > > example, and a boost::function<Controller&> or
> > > boost::function0<Controller&> in the second snip... I get
immense
> > > compiler errors, so I'm not sure where I messed up.
> > >
> > > What am I doing wrong?
> >
> >
> > Yahoo! Groups Sponsor
> > ADVERTISEMENT
> > [ericsson_300x250.jpg]
> > Info: <http://www.boost.org>
> > Wiki: <http://www.crystalclearsoftware.com/cgi-
bin/boost_wiki/wiki.pl>
> > Unsubscribe: <mailto:boost-users-unsubscribe_at_y...>
> >
> >
> > Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service.
> >
>
> --
> --
> -- Jaakko Järvi email: jajarvi_at_c...
> -- Post Doctoral Fellow phone: +1 (812) 855-3608
> -- Pervasive Technology Labs fax: +1 (812) 855-4829
> -- Indiana University, Bloomington


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