这与以下问题有关:是否必须在成员定义之外重复类模板的 requires 子句?
换句话说,给定以下模板化 struct 的代码A,需要为foo()函数定义重复requires 子句(根据上面链接问题中引用的标准段落)
template <typename T>
requires std::integral<T> //'requires-clause'
struct A
{
void foo();
};
template <typename T>
requires std::integral<T> //This 'requires-clause' is required by the standard to be reiterated
void A<T>::foo()
{
//
}
//Specialisations do not require explicit 'requires-clause'
template <>
void A<int>::foo()
{
//
}
//Specialisation with a type that does not meet the constraint raises a compile-time error
template <>
void A<double>::foo() //Not …Run Code Online (Sandbox Code Playgroud)