decltype可让编译器找出表达式的类型。

map<string,float> coll;
decltype(coll)::value_type elem;

新的函数声明语法

template<typename T1, typename T2>
auto add(T1 x, T2 y) -> decltype(x+y){
    return x+y;
}

float c=add(5.4f,3);
cout<<"c="<<c<<endl;

 

相关文章: