让我们考虑以下代码:
#include <concepts>
template<typename X>
struct Concrete_M {
X f() const { return X{}; }
};
struct Concrete_X {};
template<typename T, typename X>
concept M = requires (T t)
{
{ t.f() } -> std::convertible_to<X>;
};
template<M<Concrete_X>>
struct C {};
const C<Concrete_M<Concrete_X>> c{};
我可以使用下面这个模板参数T
吗?
template<template<typename> typename T, typename X>
concept M = requires (T<X> t)
{
{ t.f() } -> std::convertible_to<X>;
};
我该如何更改?
template<M<Concrete_X>>
struct C {};
const C<Concrete_M<Concrete_X>> c{};
如何正确地使用更新的概念 M
?我正在寻找像这样的东西:
template<typename X, /* ... */>
struct C {};
const C<Concrete_X, /* ... */> c{};
但我不明白在 /* ... */
注释之间应该放什么。 我尝试过:
template<typename X, M<X>>
struct C {};
const C<Concrete_X, Concrete_M<Concrete_X>> c{};
但是GCC 10.0.1会引发一个错误:
(...) 'M'没有限制类型(...)