5

§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)
Ryan Burn
  • 2,126
  • 1
  • 14
  • 35
  • 2
    Complete aside: someone who clearly doesn't read many C++1z language-lawyer questions tried to close this as a "fix meh codz" question. ;) (admittedly, the code example does improve it!) – Yakk - Adam Nevraumont Jan 21 '16 at 19:10

1 Answers1

3

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.

Columbo
  • 60,038
  • 8
  • 155
  • 203
  • 1
    That's not the right fix, because the normal form is also used to test whether the constraints are actually satisfied. So if you fix it that way it might work for subsumption, but not for actual use. (Also, it's not underspecified; the currently specification is clear how `(C && ...)` is to be handled: as an atomic predicate constraint.) – T.C. Jan 22 '16 at 02:24
  • @T.C. I am aware of all that. I am currently writing up a proper fix and will edit once I'm done. – Columbo Jan 22 '16 at 09:18
  • @T.C. Ah, now I found the proper fix, I think. Filed an issue with that resolution. – Columbo Jan 23 '16 at 13:30
  • @T.C. My resolution was indeed fitting: http://cplusplus.github.io/concepts-ts/ts-active.html#28 – Columbo Mar 08 '16 at 23:21