当然,您可以使用默认模板参数:
template <typename T, typename U, typename V = U>
template <typename T, typename U = int, typename V = std::vector<U> >
标准库一直都是这样做的——大多数容器都有两到五个参数!比如unordered_map其实就是:
template<
class Key, // needed, key type
class T, // needed, mapped type
class Hash = std::hash<Key>, // hash functor, defaults to std::hash<Key>
class KeyEqual = std::equal_to<Key>, // comparator, defaults to Key::operator==()
class Allocator = std::allocator<std::pair<const Key, T>> // allocator, defaults to std::allocator
> class unordered_map;
通常您只是将其用作std::unordered_map<std::string, double>,而无需进一步考虑。