我不知道C++ stl谓词是如何实现的?例如在copy_if() http://www.cplusplus.com/reference/algorithm/copy_if/关于C++ stl谓词的实现
根据Effective STL,谓词按值传递。为INT下面的代码,
struct my_predicate{
int var_1;
float var_2;
bool operator()(const int& arg){
// some processing here
}
}
如何copy_if()
实施关于向过往my_predicate的价值?这里有var_1
和var_2
。对于其他谓词,结构中可能有不同的变量。
如果通过引用或指针传递,这对我来说非常合理。
非常感谢!
请注意,大多数谓词包含* no *变量。通过一无所有将是相当浪费。 –
现在“首选”的方式是通过转发参考。 – Jarod42