c++ - 为什么 stl 算法按值获取可调用对象?
问题描述
我在尝试类似的东西时偶然发现了这一点
#include <vector>
#include <algorithm>
struct pred { //not copyable
pred () {}
bool operator()(int) const { return false; }
pred( pred && ) {}
};
int main () {
std::vector<int> a{1,2,3};
std::vector<int> b{};
auto p = pred{};
//std::copy_if(a.begin(), a.end(), std::back_inserter(b), p); // this fails
std::copy_if(a.begin(), a.end(), std::back_inserter(b), std::move(p));
}
为什么 stl 算法不能接受“操作”的通用引用?
PS:抱歉,如果这是重复的,如果不是,我会感到惊讶..
解决方案
推荐阅读
- node.js - 如何在 Node Js 应用程序中迭代 JSON 数据
- assembly - 如何更改 Assembly 中的前景色?
- tsql - SQL找出增加序列的减少
- java - 如何从 Java 中的字符串中删除非 ASCII 字符(AltCodes)
- python - 如何使用类似请求 python 的 selenium 获取带参数的 URL
- python - Python 3:time.perf_counter() 输出与 Coursera 上的程序处理时间不匹配
- python - Python speech_recognition 不理解我并返回 UnknwonValueError
- docker - 将环境变量传递给数据属性
- visual-studio - 使用 Visual Studios 2019 导致 100% 磁盘使用率
- laravel - Where do I add custom verification for user registration