Boost logo

Ublas :

From: Russ (c.r.coggrave_at_[hidden])
Date: 2006-04-25 18:31:57


>
> Maybe I misunderstand your functor, but I thought it should be
> lt_functor<double, double, bool > myfunctor;
> And its apply() method should be something like
>
> bool apply(double e1, double e2) const { return e1 < e2 ? r1_ : r2_; }
>

I think you are right :)

> > // Setup the functor arguments
> > // These could setup in the functor constructor, but just want to show
> > // a more general implementation
> > functor.set( true, false );
> > // Perform elementwise operation on vectors
> > v3 = binary_vector_elementwise( v1, v2, myfunctor );
> > // Change functor setup
> > functor.set( false, true );
> > // Perform elementwise operation on vectors
> > v4 = binary_vector_elementwise( v1, v2, myfunctor );
>
> This is ok if binary_vector_elementwise keeps a copy of the functor as
> a member variable (which it should), instead of a reference to it. But
> just to be on the safe side, I would instanciate a new functor for the
> second call. In fact, to force this, I would argue that you don't need
> the set() method in your functor, and r1 and r2 should be setup at
> construction time:
>
> lt_functor<double, double, bool > myfunctor(true, false);
> v3 = binary_vector_elementwise( v1, v2, myfunctor );
> lt_functor<double, double, bool > another_functor(false, true);
> v4 = binary_vector_elementwise( v1, v2, another_functor);
>

I agree the constructor should force the user to provide initial values for r1
and r2. I was trying to make the functor object as flexible as possible by
adding the set() method. Its a matter of taste I guess, and I don't have any
strong objections if we don't implement set(). I was just trying to emphasis
that the values are set at runtime, not compile time.

Regards,

Russ