简体   繁体   English

如何在约束的部分排序中使用折叠表达式?

[英]How are fold expressions used in the partial ordering of constraints?

§14.10.3 Partial ordering by constraints [temp.constr.order] of N4553 specifies that constraint expressions formed of concepts and logical operators should be partially ordered and used to select the best viable function in cases of overloading. §14.10.3通过约束[temp.constr.order]偏序 N4553指定的概念和逻辑运算符形成的约束表达式应部分有序和用于选择在超载的情况下,最好可行函数。 But does this also apply to constraint expressions using fold expressions of logical operators? 但这是否也适用于使用逻辑运算符的折叠表达式的约束表达式?

For example, is gcc correct to give an ambiguous overload error here or is the code valid, printing "c"? 例如,gcc是否正确以在此处给出不明确的过载错误或者代码是否有效,打印“c”?

template <class T> concept bool A = std::is_move_constructible<T>::value;
template <class T> concept bool B = std::is_copy_constructible<T>::value;
template <class T> concept bool C = A<T> && B<T>;

template <class... _tx>
  requires (A<_tx> && ...)
void g(_tx... tx) {
  std::cout << "a\n";
}

template <class... _tx>
  requires (C<_tx> && ...)
void g(_tx... tx) {
  std::cout << "c\n";
}

f(3, 2.0)

Fold expressions are currently not handled during partial ordering by constraints ([temp.constr.order]). 在约束([temp.constr.order])的部分排序期间,当前不处理折叠表达式。

This can be fixed by specifying that the atomic constraint P && ... subsumes Q || ... 这可以通过指定原子约束P && ...包含Q || ... Q || ... and Q && ... iff P subsumes Q . Q || ...Q && ...如果P包含Q In that case, it is rather obvious that the first overload's constraints are subsumed by the second overload's but not vice versa, making the latter more constrained. 在这种情况下,很明显第一次过载的约束被第二次过载所包含但反之亦然,这使得后者更受约束。

This will be resolved via concepts issue #28 . 这将通过概念问题#28解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM