Boost logo

Boost :

Subject: Re: [boost] [range][1.43] is boost::get or boost::at missing?
From: Neil Groves (neil_at_[hidden])
Date: 2010-04-29 14:31:57


On Thu, Apr 29, 2010 at 6:53 PM, vicente.botet <vicente.botet_at_[hidden]>wrote:

> Hi,
> I'm wondering if a checked element access via at() is missing for Random
> Access ranges.
>
>
It doesn't exist yet. I can implement one for after release 1.43.

I imagine a non-member function something like this:

template<typename RandomAccessRange>
typename boost::range_reference<RandomAccessRange>::type
at(RandomAccessRange& rng, typename
boost::range_difference<RandomAccessRange>::type index)
{
    BOOST_RANGE_CONCEPT_ASSERT(( ... ));
    if (index < 0 || index >= boost::size(rng)) throw std::out_of_range( ...
);
    return *(boost::begin(rng) + index);
}

... const version ...

Is this the sort of thing you are suggesting? Or would you expect something
else for the second argument type to promote to the appropriate unsigned
type and circumvent the check for < 0?

Best,
> _____________________
> Vicente Juan Botet Escribá
> http://viboes.blogspot.com/

I like the idea. I would be interested in feedback from others. I also
invite a confirmation that my understanding of your request is correct.

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