为什么C++标准中没有 std::copy_until 功能
Why there is no std::copy_until function in C++ standard?
C++标准库提供了非常棒的东西(std::copy
,std::count
,std::remove
等),但我不知道为什么没有std::copy_until
,它会将数据从输入迭代器复制到输出,直到测试(例如lambda)返回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;
}
我以为只是没有人写论文或其他东西,但也许这样的功能有点糟糕/表明我的代码设计错误?
"
为什么C++标准中没有std::copy_until
函数?"的答案可能是其中之一:
- 从来没有人费心为它写提案。
- 有人提出,但ISO委员会认为它不够有用。
- 它被认为是有用的,但与其他新的 C++11 算法不同,缺乏现有实现或扩展的经验,因此保守的选择是不添加它。
另请参阅"更多 STL 算法(修订版 2)"提案。尽管它没有提到类似copy_until
的东西,但它揭示了一些为什么某些算法(如copy_if
)被添加而其他算法(如lexicographical_compare_3way
)没有。
相关文章:
- std::filesystem::copy throws filesystem_error
- 如何在 Boost.Asio 中使用 Zero-copy sendmsg/receive
- C++ 一个lambda浅拷贝const Type&如果它被赋予一个命名捕获,如[copy=val](){}?
- QML/C++/QObject Struct Copy
- C++赋值运算符,我们可以用 copy 替换它吗?
- 为什么我使用 std::copy() 收到运行时错误(分段错误)?
- 如何解决C++中声纳库贝静态代码分析错误"Explicitly define the missing copy constructor, move constructor .."
- 如何使用 std::copy 当类有"无符号字符和运算符[]"时
- std::copy 导致运行时检查失败 #2
- 为什么 Clang 在命名空间'std'中没有名为 'copy' 的成员给出错误
- 这在C++ "It does not own the underlying data, and so is cheap to copy or assign"中意味着什么
- 为什么使用 <uint8_t>MSVC 2015 编译器的 std::vector::insert 比 std::copy 快 5 倍?
- 对于输出,std::copy是否比std::cout快
- C++中的'deep copy'构造函数
- 复制初始化:为什么即使关闭了复制省略,也没有调用move或copy构造函数
- Qt中的QFile::copy(source,dest)的实现有时是错误的吗?
- 有些时候,阶级必须"default copy c'tor" ?当我做"new Type[..]"时会发生什么?
- MSVC++ 17 std::copy 期望自定义迭代器的"operator -"
- 调用了Copy ctor而不是move ctor
- std::copy,std::copy_backward和重叠范围