[range][1.43] is boost::get or boost::at missing?

Hi, I'm wondering if a checked element access via at() is missing for Random Access ranges. Best, _____________________ Vicente Juan Botet Escribá http://viboes.blogspot.com/

On Thu, Apr 29, 2010 at 6:53 PM, vicente.botet <vicente.botet@wanadoo.fr>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

----- Original Message ----- From: "Neil Groves" <neil@grovescomputing.com> To: <boost@lists.boost.org> 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@wanadoo.fr>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
participants (2)
-
Neil Groves
-
vicente.botet