Bind/lambda arithmetic question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bind/lambda arithmetic question

Stephen Gross
Ok, I want to create a functor that takes no arguments and returns a double.
Furthermore, I want this functor to be composed of functors itself. For
instance:

=============================
struct Foo
{
  double getX() const{ return 5; }
  double getY() const { return 10; }
};

Foo f;

double z = (boost::bind(&Foo::getX, boost::ref(f)) / boost::bind(&Foo::getY,
boost::ref(f))) ();
====================

The above code, however, generates the following error:

error: no match for 'operator/' in 'boost::bind(R (T::*)()
   const, A1) [with R = double, T = Foo, A1 =
   boost::reference_wrapper<Foo>](boost::ref(T&) [with T = Foo]()) /
   boost::bind(R (T::*)() const, A1) [with R = double, T = Foo, A1 =
   boost::reference_wrapper<Foo>](boost::ref(T&) [with T = Foo]())'

Is there a way to make the division operation of two functors work in this
example?

Thanks,
--Steve

Stephen Gross
Case Western School of Medicine
Cleveland, OH

"By Grabthar's hammer, by the sons of Worvan, you shall be avenged." - Dr.
Lazarus


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Bind/lambda arithmetic question

Nat Goodspeed
> -----Original Message-----
> From: [hidden email] [mailto:boost-users-
> [hidden email]] On Behalf Of Stephen Gross
> Sent: Friday, February 03, 2006 12:52 PM
> To: Boost
> Subject: [Boost-users] Bind/lambda arithmetic question
>
> =============================
> struct Foo
> {
>   double getX() const{ return 5; }
>   double getY() const { return 10; }
> };
>
> Foo f;
>
> double z = (boost::bind(&Foo::getX, boost::ref(f)) /
> boost::bind(&Foo::getY,
> boost::ref(f))) ();
> ====================

[Nat] This might work better if you were to use boost::lambda::bind()
rather than boost::bind()?

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users