|
Boost : |
From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2006-04-15 15:06:41
On 4/15/06, David Abrahams <dave_at_[hidden]> wrote:
> "Daniel Walker" <daniel.j.walker_at_[hidden]> writes:
>
> > On 4/11/06, David Abrahams <dave_at_[hidden]> wrote:
> >> Thorsten Ottosen <thorsten.ottosen_at_[hidden]> writes:
> >>
> >> >> cannot have overloads (in C++98) taking containers/ranges:
> >> >>
> >> >> fn( Iterator first, Iterator last )
> >> >> fn( Iterator first, Iterator last, Functor f )
> >> >> fn( Range rng )
> >> >> fn( Range rng, Functor f )
> >> >>
> >> >> as the last overload is ambiguous. Concepts will allow this to be resolved
> >> >> as a Functor will not match the Iterator requirements :).
> >> >
> >> > you can use enable_if on the latter and disable it the two types are the
> >> > same.
> >>
> >> Not if you happen to have a type that is both a valid range and a
> >> valid function object.
> >>
> >> Yes, that's a corner case, but it's the corner of a large floating
> >> block of ice.
> >
> > For this idiom, I use boost::iterator_range like so,
> >
> > fn( Iterator first, Iterator last )
> > fn( Iterator first, Iterator last, Functor f )
> > fn( boost::iterator_range<Iterator> rng )
> > fn( boost::iterator_range<Iterator> rng, Functor f )
>
> This is not generic. Now you can't pass other valid Ranges
> (e.g. std::vector<T>) as the first argument to fn.
Yeah, I know. This is just a work-around because the generic version
isn't possible today due to the overload ambiguity. You can indirectly
use the functions with other valid Ranges like vector, but it's a
hassle because you first have to convert them using
make_iterator_range(). In some circumstances, for the time being, this
may be acceptable for this particular idiom (overloading algorithms to
take both iterators and ranges), but really I agree that it further
illustrates the need for in-language support for concepts in a future
version of C++ in order to make the overloads generic.
Daniel Walker
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk