mardi 30 mai 2017

Why are there const overloads of mutating Boost.Range algorithms?

The documentation (and the implementation) of Boost.Range shows overloads of the mutating algorithms that take const refs as arguments. For instance Boost.Range's Sort documentation shows:

template<class RandomAccessRange>
RandomAccessRange& sort(RandomAccessRange& rng);

template<class RandomAccessRange>
const RandomAccessRange& sort(const RandomAccessRange& rng);

template<class RandomAccessRange, class BinaryPredicate>
RandomAccessRange& sort(RandomAccessRange& rng, BinaryPredicate pred);

template<class RandomAccessRange, class BinaryPredicate>
const RandomAccessRange& sort(const RandomAccessRange& rng, BinaryPredicate pred);

What is the point of overloads 2 and 4? Sure it's nice to be able to pass temporaries, but then const& makes this point kinda of moot. Rvalue-references would be most welcome, but it is my understanding that their support in Boost.Range is too invasive, and is "deferred" to the adoption of Range.V3 (it would be nice if meanwhile it were part of Boost).

Aucun commentaire:

Enregistrer un commentaire