Boost logo

Boost :

Subject: Re: [boost] [RangeEx] Range & RangeEx
From: David Abrahams (dave_at_[hidden])
Date: 2008-09-14 09:21:02


on Sat Sep 13 2008, Steven Watanabe <watanabesj-AT-gmail.com> wrote:

> AMDG
>
> Neal Becker wrote:
>> I'm reading algorithm.hpp. I'm puzzled about one thing.
>>
>> There are overloads of lots of algs, such as find.
>> 1 template<typename Rng,typename Val>
>> inline BOOST_DEDUCED_TYPENAME boost::range_iterator<Rng>::type
>> find(Rng & rng,Val const & val)
>> {
>> return std::find(boost::begin(rng),boost::end(rng),val);
>> }
>>
>> 2 template<typename Rng,typename Val>
>> inline BOOST_DEDUCED_TYPENAME boost::range_iterator<const Rng>::type
>> find(Rng const & rng,Val const & val)
>> {
>> return std::find(boost::begin(rng),boost::end(rng),val);
>> }
>>
>> I'm puzzled what's different between 1, where Rng is "const T", vs 2, where
> Rng is "T"? In other words, why do we need both? The only thing that seems
> different is "boost::begin(rng)", but that's already overloaded for const.
>>
>
> If only the Rng& version were provided it would be impossible to
> pass a rvalue range to find. If only the const Rng& version were
> provided, we would always add const even when it isn't needed (I'm
> not sure that this matters for find, since it is a non-mutating algorithm,
> though)

FWIW, the property map version of find doesn't have this problem.
Property maps have the potential to eliminate lots of ugliness
associated with const/mutable accesses.
      

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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