|
Boost : |
From: John Torjo (john.lists_at_[hidden])
Date: 2003-11-20 12:37:39
Matthew Wilson wrote:
>>Now that I think about it, a range concept does not even need to be so
>
> complicated.
>
>>As explained above (in the original message):
>>- a range is a pair of iterators
>>- it has typedefs for value_type,pointer,reference
>> (no const_pointer,no const_reference)
>>- it's got begin() and end()
>>- it's got an operator bool() that returns true if the
>> range is non-empty.
>
>
> I'm still of the opinion that all a range needs is ++(), bool() and *().
> Having said that, begin() and end() are starting to look attractive, from a
> practical pov. Hopefully others can shed light on where in the continuum
> between our ideas they lie. (Perhaps they'll lie outside it! :)
>
Matt, that is not true.
Again, I've used it in real code, where I would find an element, and had to go
to the previous one.
// real-life code
crange< const snapshots_array> found = rng::lower_bound( m_snapshots,
mk_dummy_snapshot( m_current), snapshot_by_time);
if ( found.begin() != m_snapshots.begin() )
// go to the first element whose time is earlier than current
--found;
It all depends on the situation at hand. It the iterator can do it, so the range
should.
Best,
John
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk