|
Boost : |
Subject: Re: [boost] [range] Proposal: addition of front(), back(), at(), operator[]
From: Neil Groves (neil_at_[hidden])
Date: 2014-03-23 16:32:32
iterator_range already has front() and back() functions. These are not part
of the Range Concept since we want to be able to model them
non-intrusively. The iterator_range and sub_range classes can be used to
wrap other iterator pairs or ranges and provide most of the member
functions that you are suggesting.
> 3. at()
> returning the reference to the i-th element of the range
> precondition (throw std::out_of_range or assert): index < size(rng)
>
> For RandomAccessRange
> return *(begin(rng) + index);
>
>
operator[] is implemented. An at(index) function can be written that throws
upon out-of-range. I have not provided one.
> For SinglePassRange it could iterate over the range and return the
> required element
>
> For me, non-throwing at() would be more useful however this behavior won't
> be intuitive. So the following should also be provided:
>
> 4. sub(), subscript(), el(), element(), at_index(), at_(), index(),
> indexed(), access(), operator[], ...?
> the implementation of indexing operator[]
> same as 3 but instead of throwing an assert would be used
>
> The use of operator[] could be similar to this:
>
>
Already exists for iterator_range.
> {
> using boost::range::subscript_operator;
> rng[index];
> }
>
> So not very convenient. But maybe you have a better idea?
>
>
Perhaps this is useful:
http://www.boost.org/doc/libs/1_55_0/libs/range/doc/html/range/reference/utilities/iterator_range.html
I believe that everything you have asked for is already present except a
throwing at() function which might be a nice addition.
> Regards,
> Adam
>
> Regards,
Neil Groves
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk