Boost logo

Ublas :

From: Vardan Akopian (vakopian_at_[hidden])
Date: 2006-04-24 17:13:53


On 4/24/06, Russ <c.r.coggrave_at_[hidden]> wrote:
> Gunter Winkler <guwi17 <at> gmx.de> writes:
>
> >
> > On Monday 24 April 2006 16:05, Russ wrote:
> >
> > > However, now I think of it in terms of functors, if we consider the
> > > situation where r1 and r2 ARE known at compile time then I can probably
> > > reuse vector_binary<E1,E2,F> using a fuctor F that takes four arguments.
> > > This might be easier to implement and get going, but not as general. I
> > > think I should try and get this working before tackling the more general
> > > case above.
> >
> > Yes, this sound very reasonable. You want to combine two vectors, so you have
> > to use vector_binary and put all additional information into the functor F.
> >
>
> I think I am confusing myself now. Giving this a little more thought I realise
> that I have ALREADY implemented the senario you described above. At the start of
> this thread I mentioned that I had developed the code for
>
> V3 = lt( V1, V2 )
> where
> V3[i] = (V1[i] < V2[i])
> and the value_type for V3 is vector_expression<bool>
>
> This is implemented in terms of a vector_binary and a functor. I can confirm
> that this approach works :)
>
> So now the next step. How to implement it for the case when r1 and r2 are not
> known at compile time. At compile time, only the type of r1 and type of r2 are
> known. In this case, we need to implement vector_quad_relop, which is where the
> code I attached in my original message comes in.
>
> vector_quad_relop started out as vector_binary, with some hacking around to
> support 4 arguments. However, I have obviously gone wrong somewhere :(

It seams to me that a more generic construct would be similar to
vector_binary, but one, which would keep an instance f_ of the functor
as a member, and then call f_.apply(e1_(i), e2_(i)) instead of calling
functor_type::apply(e1_(i), e2_(i)).
Then you could keep r1 and r2 in f_ and define apply() the way you want.
This would be very similar to e.g. how STL containers handle custom comparators.

Cheers
-Vardan