据我了解,在C++ 0x中模板的别名将使我们能够做到以下几点:灵活的C++模板别名0X
template <typename T>
using Dictionary = std::map< std::string, T >;
Dictionary<int> ints;
ints[ "one" ] = 1;
ints[ "two" ] = 2;
我有两个问题:
首先,我们能够做到这一点(绑定到任何类型的,或者只是模板):
template <typename Iter>
using ValueType = std::iterator_traits<Iter>::value_type;
其次,将使用别名需要在模板中typename
关键字的使用,如:
template <typename Iter>
typename ValueType<Iter> sum(Iter first, Iter last) { ... }
//^required?
还是在别名声明中需要吗?
using ValueType = typename std::iterator_traits<Iter>::value_type;
// ^required?
或者都不是?