The implementation of boost::lower_bound
(found here) in Range 2.0 takes its argument by value.
Why is this? std::lower_bound
takes its argument by const ref - see here
While it is difficult to know for sure the reason for this, there are two things to keep in mind:
The general reason for passing by value is when you end up making a copy in the function. Also, passing by value can potentially invoke the move constructor on prvalues/xvalues and the copy constructor on lvalues.
In the recent versions of the boost library boost::lower_bound
uses std::lower_bound
in its implementation. Boost 1.59 has the following implementation for the overloads of boost::lower_bound
mentioned in your link:
template< class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type
lower_bound( const ForwardRange& rng, Value val )
{
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
return std::lower_bound(boost::begin(rng), boost::end(rng), val);
}
template< range_return_value re, class ForwardRange, class Value >
inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
lower_bound( const ForwardRange& rng, Value val )
{
BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
return range_return<const ForwardRange,re>::
pack(std::lower_bound(boost::begin(rng), boost::end(rng), val),
rng);
}
This has now been fixed by this issue.
There may be historical reasons for taking the argument by value. See this answer about function objects passed by value to standard algorithms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With