【发布时间】:2017-10-31 02:09:05
【问题描述】:
Boost.Range 的文档(和实现)显示了以 const refs 作为参数的变异算法的重载。例如Boost.Range's Sort documentation 显示:
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);
重载 2 和 4 的意义何在?当然,能够通过临时人员很好,但是const& 使这一点变得毫无意义。 Rvalue-references 将是最受欢迎的,但我的理解是它们对 Boost.Range 的支持过于侵入性,并且“推迟”到 Range.V3 的采用(如果同时它是 Boost 的一部分,那就太好了)。
【问题讨论】:
-
从源代码来看,它似乎是针对
const的容器,因为容器的状态不能被修改,但底层元素可以被改变, -
const iterator_pair<It, It>是一个常量范围,但这并不意味着目标元素无法排序...
标签: c++ c++11 boost c++14 range-v3