|
Boost : |
From: helmut.zeisel_at_[hidden]
Date: 2001-07-26 07:00:50
--- In boost_at_y..., "Philip Nash" <philip.nash_at_c...> wrote:
> .. adding to the debate of container interface vs range iterator
interface:
Just to change the terminology a little:
IMHO, we have no container interface vs. range interface debate.
We have just 2 different possible range interfaces.
Interface 2 is the classical STL interface that
needs 2 interators (begin, end) to specify a range.
Interface 1 is only slightly differently
and needs 1 object (offering a begin() and an end() method)
to specify a range.
By default, every STL container already offers Interface 1.
As demonstrated in my code example posted previously,
it is easy to write a make_range function
that creates a range object from a pair
of iterators (begin, end).
Interface 2 has the advantage that it is used
in the standard C++ algorithms.
It has the disadvantage that there is no possibility
(or at least that I do not know one)
to switch to interface 1 without writing
a second wrapper algorithm for every existing standard algorithm.
Interface 1 needs only class range and function make_range
to offer an interface 2 for every client that
needs the different interface.
The disadvantages are that
a) it is not the usual standard interface, and
b) it is not clear to me whether make_range
can work without perfomrmance loss.
Using interface 1 is shorter for
the default range begin(), end() in a container,
and longer for every other range,
compared with interface 2.
The decision which interface to prefer
might depend on the most common
applications of the algorithm(s).
Helmut
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk