2017-12-03 164 views

回答

6

锵蝽(#34091

[dcl.type.class.deduct]

一种用于推导的类类型的占位符也可以在使用[...] 或作为简单型说明符explicit type conversion (functional notation)。推导出的类类型的占位符不应出​​现在任何其他上下文中。 [实施例:

template<class T> struct container { 
    container(T t) {} 
    template<class Iter> container(Iter beg, Iter end); 
}; 

template<class Iter> 
container(Iter b, Iter e) -> container<typename std::iterator_traits<Iter>::value_type>; 
std::vector<double> v = { /* ... */ }; 

container c(7);       // OK, deduces int for T 
auto d = container(v.begin(), v.end()); // OK, deduces double for T 
container e{5, 6};      // error, int is not an iterator 

- 端示例]