为什么C++标准中没有std::copy_until函数?

Why there is no std::copy_until function in C++ standard?

C++ 标准库提供了非常棒的东西(std::copystd::countstd::remove 等),但我不知道为什么没有 std::copy_until,这会将数据从输入迭代器复制到输出直到测试(例如 lambda)returns true.

下面是示例实现:

template<class inputIt, class outputIt, class comp_t>
outputIt copy_until(inputIt in, outputIt out, comp_t comp) {
    while (comp(*in)) {
        *out = *in;
        ++out;
        ++in;
    }

    return out;
}

我认为只是没有人写过论文或其他东西,但也许这样的功能在某种程度上很糟糕/暗示我的代码设计错误?

"Why there is no std::copy_until function in C++ standard?"的答案可能是以下之一:

  • 从来没有人为它写过提案。
  • 有人提议,但 ISO 委员会认为它不够有用。
  • 它被认为是有用的,但与其他新的 C++11 算法不同,它缺乏现有实现或扩展的经验,因此保守的选择是不添加它。

另见 "More STL algorithms (revision 2)" proposal。尽管它没有提到像 copy_until 这样的东西,但它阐明了为什么添加了某些算法(如 copy_if)而其他算法(如 lexicographical_compare_3way)没有。