gpt4 book ai didi

c++ - 是否在声明内的参数替换后评估 require-clauses?

转载 作者:太空狗 更新时间:2023-10-29 21:35:38 26 4
gpt4 key购买 nike

在 C++ 标准 N4618/[temp.deduct] (§14.8.2) 中,以下示例 (§14.8.2/7) 演示了如何按词法顺序执行模板参数替换:

 template <class T> struct A { using X = typename T::X; };
template <class T> typename T::X f(typename A<T>::X);
template <class T> void f(...) { }
template <class T> auto g(typename A<T>::X) -> typename T::X;
template <class T> void g(...) { }
void h() {
f<int>(0);// OK, substituting return type causes deduction to fail
g<int>(0);// error, substituting parameter type instantiates A<int>
}

我期望 requires-clauses 内容在声明内容之前也被评估。我预计以下修改不会产生任何编译错误:

 template <class T> struct A { using X = typename T::X; };
template <class T> typename T::X f(typename A<T>::X);
template <class T> void f(...) { }
template <class T>
requires false
auto g(typename A<T>::X) -> typename T::X;
template <class T>
requires true
void g(...) { }
void h() {
f<int>(0);// OK, substituting return type causes deduction to fail
g<int>(0);// error, substituting parameter type instantiates A<int>
}

实际上 GCC 告诉我仍然有错误。是概念TS中陈述的行为吗?

最佳答案

是的。请参阅 N4630 中的注释[temp.deduct]/5:

The satisfaction of constraints (14.10) associated with the function template specialization is determined during overload resolution (13.3), and not at the point of substitution.

关于c++ - 是否在声明内的参数替换后评估 require-clauses?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41802487/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com