From: Vladimir Prus (ghost_at_[hidden])
Date: 2001-11-12 04:23:41


Aleksey Gurtovoy wrote:

> For all algorithms that take an iterator pair (i.e. two iterator
> parameters that designate a single input/forward/etc. sequence) it
> makes sense and is very practical to have a version (wrapper) that
> takes a single sequence argument - a model of Sequence concept,
> e.g.
> template<typename InputSequence, typename UnaryFunction>
> inline
> UnaryFunction
> for_each(InputSequence const& seq, UnaryFunction const& f)
> {
> return std::for_each(
> boost::begin(seq)
> , boost::end(seq)
> , f
> );
> }

There are two problems, good solutions for which I'm yet to hear:
1. std::adjacent_find(ForwardIterator, ForwardIterator);
   std::adjacent_find(ForwardIterator, ForwardIterator,
BinaryPredicate);
When
   adjacent_find(const Sequence&);
   adjacent_find(const Sequence&, BinaryPredicate)
are added, there will be ambiguity when calling the function with
two arguments, won't it?
2. What will you do about mutating algorithms?
sort(Sequence&);
Somebody then writes:
... filter(const Sequence&, Predicate);
sort(filter(v, <some functional object>));
But oops! filter returns rvalue, which can't be bound to non-const
reference. The only possibility is to specialize algorithm for
derivatives of some fixed class.

Regards,
Vladimir