Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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"?

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)
like image 767
Ryan Burn Avatar asked Oct 19 '22 17:10

Ryan Burn


1 Answers

Fold expressions are currently not handled during partial ordering by constraints ([temp.constr.order]).

This can be fixed by specifying that the atomic constraint P && ... subsumes Q || ... and Q && ... iff P subsumes 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.

like image 94
Columbo Avatar answered Oct 21 '22 15:10

Columbo