简体   繁体   English

具有默认类的模板参数列表

[英]Template parameter list with default class

Does anyone have an example for 2 and 3 ?有人有23的例子吗? I try to understand the writing style of the standard, and other documentations about C++.我尝试了解标准的写作风格,以及其他有关 C++ 的文档。 In specific here the template documentation.特别是这里的模板文档。

Both is probably wrong, but I try to understand their differences.两者都可能是错误的,但我试图理解它们的差异。 Source: https://en.cppreference.com/w/cpp/language/template_parameters来源: https : //en.cppreference.com/w/cpp/language/template_parameters

template < parameter-list > typename(C++17) |模板 < 参数列表 > 类型名(C++17) | class name(optional) (1)类名(可选)(1)

template < parameter-list > typename(C++17) |模板 < 参数列表 > 类型名(C++17) | class name(optional) = default (2)类名(可选)= 默认值 (2)

template < parameter-list > typename(C++17) |模板 < 参数列表 > 类型名(C++17) | class ... name(optional) (3) (since C++11)类 ... 名称(可选) (3) (C++11 起)

1) A template template parameter with an optional name. 1) 具有可选名称的模板模板参数。

2) A template template parameter with an optional name and a default. 2) 具有可选名称和默认值的模板模板参数。

3) A template template parameter pack with an optional name. 3) 带有可选名称的模板模板参数包。

I am not sure if I interpret this correctly.我不确定我是否正确解释了这一点。 As far as I understand...据我所理解...

// 2
template <typename T, typename Y> class Foo = default; // this can't be right, can it?

// 3
template <typename T, typename Y> class ... Foo;

The page you quote has an example for (2):您引用的页面有(2)的示例:

template<
    typename K,
    typename V,
    template<typename> typename C = my_array // C is a template template parameter
>
class Map
{
    C<K> key;
    C<V> value;
};

(I reformatted the code to add comment.) (我重新格式化了代码以添加注释。)

Note that neither K nor V in above example is a template template parameter.请注意,上面示例中的KV都不是模板模板参数。

Form (3) would look like:表格 (3) 看起来像:

template<template<typename> typename... Args> // Args is a template template parameter pack
struct TPL {};

Note that template template parameters are a weird beast.请注意,模板模板参数是一个奇怪的野兽。 Usually you only need type template parameters (as in your example) and non-type template parameters .通常你只需要类型模板参数(如你的例子)和非类型模板参数 The cppreference page has detailed description for them. cppreference 页面对它们有详细的描述。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM