|
Boost : |
From: Matias Capeletto (matias.capeletto_at_[hidden])
Date: 2007-05-24 13:44:35
On 5/24/07, Thorsten Ottosen <thorsten.ottosen_at_[hidden]> wrote:
> Matias Capeletto skrev:
> > On 5/23/07, "JOAQUIN LOPEZ MU?Z" <joaquin_at_[hidden]> wrote:
> >> ----- Mensaje original -----
>
> [snip]
>
> >>> 2) In any case do you think that including typedef for the returned
> >>> range type will make code more readable?
> >>> The idea is to define:
> >>>
> >>> typedef -range_type- sub_range; // the name can be different
> >>> typedef -const_range_type- const_sub_range;
> >>>
> >>> So the user code will look like this:
> >>>
> >>> typedef bimap<string,int> bm_type;
> >>> bm_type bm;
> >>> //...
> >>> bm_type::left_sub_range r = bm.left.range(...,...);
> >> I am not sure. On one hand, the syntax above is obviously
> >> more concise, but on the other hand a casual reader would
> >> have to look up what sub_range is to fully understand the
> >> code, whereas the std::pair is self explanatory and moreover
> >> it's honored by the tradition of equal_range().
I think I will leave the range function return a pair<iter,iter> like
equal_range in the end.
> > At least for Boost.Bimap, compare:
> >
> > std::pair<
> > bm_type::map_by<name>::const_iterator,
> > bm_type::map_by<name>::const_iterator
> >
> >> r = bm.by<name>().range(...,....);
> >
> > with:
> >
> > bm_type::map_by<name>::const_sub_range r = bm.by<name>().range(...,....);
> >
> > Maybe "sub_range" is not the better word. IMO it is not a bad election.
>
> boost::sub_range< bm_type::map_by<name> >
> r = bm.by<name>().range(...,...);
>
> is not that bad IMO. This should work with or without dependency on
> Boost.Range. Without dependency there might be an extra conversion, I
> haven't timed code to see if it really matters.
If bm is const I think we have to write:
boost::sub_range< const bm_type::map_by<name> >
r = bm.by<name>().range(...,...);
that it is not bad anyway.
But I really like the look of the following code:
bm_type::map_by<name>::const_iterator_range r = bm.equal_range(...);
bm_type::map_by<name>::iterator_range r = bm.range(...,...);
Are you against provide these typedefs?
(maybe with another name: sub_range, range, range_type)
Best regards
Matias
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk