【问题标题】:template-template-parameter and concepts模板模板参数和概念
【发布时间】:2019-05-08 05:53:10
【问题描述】:

模板模板参数可以写概念吗?

template<template<typename> typename T> struct A {};

我想检查T 的特定实例化是否满足概念。

例子:

template<typename F>
concept bool HasF = requires(F) {
    F::f();
};

template<typename T>
struct Test1 {
    static void f() {}
};

template<typename T>
struct Test2 {
};

template<template<typename> typename T> 
//requires HasF<T<B>> // not possible
struct A {
    struct B {
    };    
};


using x1 = A<Test1>;
using x2 = A<Test2>; // should fail

在上面的示例中,我不能使用B,因为它没有在使用时声明。

【问题讨论】:

  • 我猜template&lt;template&lt;typename&gt; typename T&gt; requires a_concept&lt;T&lt;specific_type&gt;&gt; struct A {}?
  • 好的。但是如果specific_type 只在A 内部知道呢?所以,我们不能在序言中写 requires 子句。
  • 你能举个具体的例子吗?
  • 编辑了问题。
  • 你的例子并不真正支持你的起源问题......Test1没有任何不满足HasF的特定实例化,template-template真的不指向这里(同样只需检查HasF&lt;B&gt;)。总而言之,这是一个完全不同的问题。

标签: c++ c++-concepts template-templates


【解决方案1】:
template<template<typename> typename T> requires a_concept<T<specific_type>> 
struct A {}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 1970-01-01
    相关资源
    最近更新 更多