|
Boost : |
From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2001-11-20 11:59:00
Dave Harris wrote:
> On Mon, 5 Nov 2001 02:54:50 -0600 Aleksey Gurtovoy
> (alexy_at_[hidden])
> wrote:
> > 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
> > );
> > }
>
> I meant the opposite:
>
> template <typename iterator, typename functor>
> functor for_each( iterator first, iterator last, functor f ) {
> return for_each( make_sequence( first, last ), f );
> }
>
> This allows the more primitive version of for_each to take
> advantage of any methods we add to the sequence object
> interface. If, as you suggest elsewhere, a sequence is
> something which can be modeled by a container, it can
> have container-like methods such as empty() and size().
Yes, both 'empty(seq)' and 'size(seq)' are valid expression for the models
of Forward, Bidirectional and Random Access Sequences (as currently
defined). For Input Sequence, only 'empty(seq)' expression make sense, and
'size(seq)' is unavailable for obvious reasons.
> These will clarify the algorithm's code and perhaps be
> more efficient.
They might be, but I think that the gain in the performance would be very
neglectable. IMO if you want to take advantage of a high-level container
interface, then "true" container algorithms might be a better choice (yes,
it's different from what we've been talking about). You need to build a
reasonable container classification for that first, of course ;).
-- Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk