小编Not*_*mer的帖子

为什么类外成员模板定义需要重复其声明“requires-clause”

这与以下问题有关:是否必须在成员定义之外重复类模板的 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)

c++ templates language-lawyer c++-concepts

6
推荐指数
1
解决办法
217
查看次数

标签 统计

c++ ×1

c++-concepts ×1

language-lawyer ×1

templates ×1