
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) In Christ, Steven Watanabe