binder2nd
源自unary_function
。
以下代码段不起作用:
greater<int> g;
//greater is derived from binary_function
//bind2nd returns binder2nd object and binder2nd is derived from unary_function
const unary_function<int,bool> &greater_than_0 = bind2nd(g, 0);
// base class reference type holding reference to derived class object
remove_if(lst.begin(), lst.end(), greater_than_0);
//does not work
而以下代码片段有效:
greater<int> g;
const binder2nd< greater<int> > &greater_than_0 = bind2nd(g, 0);
remove_if(lst.begin(), lst.end(), greater_than_0);
unary_function
在第一个代码片段中使用虚拟虚函数是否会有所帮助。这可以改善 STL 的使用吗?