Boost logo

Boost :

From: Matias Capeletto (matias.capeletto_at_[hidden])
Date: 2007-02-26 23:23:55


On 2/26/07, Thorsten Ottosen <thorsten.ottosen_at_[hidden]> wrote:
> Matias Capeletto wrote:
> > On 2/26/07, Thorsten Ottosen <thorsten.ottosen_at_[hidden]> wrote:
>
> >>What if you make the members of the view pairs something like
> >>
> >>template< class Pair& >
> >>struct get_first
> >>{
> >> Pair& p_;
> >> operator typename Pair::first_type&() const
> >> { return p_.first; }
> >>};
> >>
> >>?
> > It is a possible way to achieve the same results. The problem with it
> > is that the size of the resulting pair will be two references bigger.
> > This option was analyze and discarded for that reason.
>
> Not understood. A pair of references pair<T&,U&>
> requires one to store 2 references. My skecth above
> would also require 2 references.

> A smart compiler might know it is the same reference store twice
> snd do some optimization.

Could you give me more information about your skecth?

The problem is to construct a relation<X,Y> class that can be viewed
as a pair<X,Y> and as a pair<Y,X>.
IMO the most efficient way to achieve this behaviour is to use the
mutant idiom in every compiler that supported it. Is your proposal
intended to improve this case?, or the case where the compiler do not
support this idiom and we must roll back our pretensions and use
references?

It is something like this

template< class Relation >
struct get_left
{
    Relation & rel;
    get_left(Relation&r) : rel(r) {}
    operator Relation::left_value_type & ()
    { return rel.left; }
};

...

template< class Relation >
left_pair_view
{
    get_left<Relation> first;
    get_right<Relation> second;
    ...
};

...

?

Regards
Matias


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk