c++ - C++ 标准库中的模板模板参数?

标签 c++ c++11 c++14

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 if Ptr is a class template instantiation of the form SomePointer<T, Args>, where Args 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/

相关文章:

c++ - 如何为析构函数指定 nothrow 异常说明符?

c++ - 这两个代码之间的区别(为什么我的数组占用额外的空间,即使我给了它一个限制)

c++ - 我在哪里可以找到标准中对 *p 和 p[0]、*(p+1) 和 p[1]、... 之间等价关系的引用?

c++ - constexpr 作为可变成员的一部分

c++ - 在 C++ 中使用托管 COM 对象

c++ - 如何暂时禁用使用 [[deprecated]] 变量的警告?

c++ - 从双指针调用函数

c++ - g++ 和 clang++ 与 operator<() 重载的不同行为

c++ - 在新的 Visual Studio 项目中包含任何 Eigen 3.3.1 文件都不会编译

C++ 2011:std::thread:并行化循环的简单示例?