
Boost : 
From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 20010728 15:02:00
Jeremy Siek wrote:
> I'm thinking the container algorithms should use the begin(c), end(c)
> syntax for maximum flexibility,
My thoughts too. And the same about other basic sequence operations: 'size',
'empty', 'front' and 'back'. That's what we have here at work:
template<class Sequence>
struct begin_algorithm
{
typedef typename sequence_algorithm_traits<Sequence>::iterator
result_type;
static result_type result(Sequence& seq)
{
return seq.begin();
}
};
template<class Sequence>
inline
typename begin_algorithm<Sequence>::result_type
begin(Sequence& seq)
{
return begin_algorithm<Sequence>::result(seq);
}
template<class Sequence>
struct end_algorithm
{
typedef typename sequence_algorithm_traits<Sequence>::iterator
result_type;
static result_type result(Sequence& seq)
{
return seq.end();
}
};
template<class Sequence>
inline
typename end_algorithm<Sequence>::result_type
end(Sequence& seq)
{
return end_algorithm<Sequence>::result(seq);
}
//...
template<class Sequence>
struct empty_algorithm
{
static bool result(Sequence const& seq)
{
return begin(seq) == end(seq);
}
};
template<class Sequence>
inline
bool empty(Sequence const& seq)
{
return empty_algorithm<Sequence>::result(seq);
}
> and that we should have a concept named something like
> "Range" to describe these things.
Actually, I think that "Sequence" is a better name for the concept,
something like this:
"A Sequence is anything to that you can apply begin/end operations in order
to get iterators for accessing the range of its elements. Any Container is a
model of Sequence, but Sequence is not necessary a container. In particular,
Sequence is not required to "own" its elements, i.e. the lifetime of an
element in a Sequence does not have to match the lifetime of the Sequence
object. Also, Sequence is not required to actually store its elements
somewhere, i.e. there is no guarantee that elements of a Sequence do all
exist at the same time  they might be created on the fly while you are
iterating the sequence. Nor is there a guarantee that more than one iterator
into a Sequence may be active at any one time. ..."
BTW, I know that SGI STL library's documentation already uses the "Sequence"
term for naming a concept that should be really called "Sequential
Container", and I find this unfortunate. Good news are that the standard
itself does not define any container concepts, so it's not too late for a
change :).
Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk