C++标准库中哪些模板(如果有的话)有一个或多个模板模板参数?
如果有很多,那么举几个例子就可以了。
如果 C++ 版本很重要,则首选 C++14/C++1y 的最新草案。
最佳答案
我不知道 C++ 标准库中有任何模板指定采用模板模板参数,但 C++11 中至少有一个标准模板具有部分特化 带有模板模板参数:std::pointer_traits
. std::pointer_traits<Ptr>::element_type
指定为:
Ptr::element_type
if such a type exists; otherwise,T
ifPtr
is a class template instantiation of the formSomePointer<T, Args>
, whereArgs
is zero or more type arguments; otherwise, the specialization is ill-formed.
为了实现这一点,您需要 SomePointer
的模板模板参数,因为它可以是任意类模板(准确地说,只要它只有类型模板参数)。这是执行此操作的 libstdc++ 帮助程序类部分特化,例如:
template<template<typename, typename...> class _SomePtr, typename _Tp,
typename... _Args>
struct __ptrtr_elt_type<_SomePtr<_Tp, _Args...>, false>
{
typedef _Tp __type;
};
关于c++ - C++ 标准库中的模板模板参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25558704/