Boost logo

Boost :

Subject: Re: [boost] [range][1.43] is boost::get or boost::at missing?
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2010-04-29 17:18:08


----- Original Message -----
From: "Neil Groves" <neil_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Thursday, April 29, 2010 8:31 PM
Subject: Re: [boost] [range][1.43] is boost::get or boost::at missing?

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?

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
_______________________________________________

Hi Neil,

Yes, you have understood perfectly my request.

I would expect however a size_type, but I see that there is no metafunction to get the size_type, such as

boost::range_size<RandomAccessRange>::type

so no need to check for < 0. The conversion from size_type to the difference type should be not an issue, as "size_type represent any non-negative value of difference_type" selon the standard, isn't it?

Thanks to taking care of this request.
Vicente


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk