且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

概念可以与模板模板参数一起使用吗?

更新时间:2023-09-19 12:23:46

概念的简化形式 type-constraint 语法:

template <Concept T>
struct C { };

仅对 Concept 的情况有效的第一个模板参数是类型参数。如果不是这种情况,则只需使用长格式语法: requires-clause

is only valid for those cases where Concept's first template parameter is a type parameter. When that is not the case, you have to simply use the long form syntax: a requires-clause:

template <template <typename> class Z>
    requires M<Z, Concrete_X>
struct C {};

第一个示例的等效长格式为:

The equivalent longer-form for my initial example is:

template <typename T> requires Concept<T>
struct C { };

长格式和短格式表示同一件事-这里没有功能不同。

The long form and short form mean the same thing - there's no functionality different here.

推荐文章