您的位置:首页 > 编程语言 > C语言/C++

utilities——C++常用仿函数(二)

2016-03-17 23:31 316 查看
utilities——C++常用仿函数

identity (证同性函数)

f(x)=x
f(x)=x

template<class T>
struct identity : public unary_function<T, T>
{
const T& operator()(const T& x) const
{
return x;
}
}


identity 的数学含义是证同性函数,即不做修改,保持原值;

std::identity<int>()(5);
// 第一对括号表示仿函数的实例化,因为其构造函数为空的默认构造
// 第二对括号表示调用括号运算符重载
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: