Date: Sun, 7 May 2023 11:34:55 -0400
On Sun, May 7, 2023 at 4:11 AM Nikl Kelbon via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Let two foos:
> This compiles:
> #include <concepts>
> #include <functional>
> template<typename A, typename B>
> bool foo(std::strict_weak_order<A, B> auto) {
> return true;
> }
> template<std::copyable A, typename B>
> bool foo(std::equivalence_relation<A, B> auto) {
> return false;
> }
> int main() {
> return foo<int, int>(std::equal_to<>{});
> }
> You say i hide ambiguity, but in fact equality of this two concepts now hides it.
> https://godbolt.org/z/bqePq7hcv
That's *not* how concepts work. They don't work individually like
this; all of the constraints are considered and they care considered
equally important.
The second `foo` has additional constrains the first lacks. The
standard *does not care* what those constraints mean; what matters is
that it *has them*. Therefore, there is some set of types `T` which
the first one can be used with but not the second. Therefore, the
second is more constrained, and is preferred when applicable.
<std-proposals_at_[hidden]> wrote:
>
> Let two foos:
> This compiles:
> #include <concepts>
> #include <functional>
> template<typename A, typename B>
> bool foo(std::strict_weak_order<A, B> auto) {
> return true;
> }
> template<std::copyable A, typename B>
> bool foo(std::equivalence_relation<A, B> auto) {
> return false;
> }
> int main() {
> return foo<int, int>(std::equal_to<>{});
> }
> You say i hide ambiguity, but in fact equality of this two concepts now hides it.
> https://godbolt.org/z/bqePq7hcv
That's *not* how concepts work. They don't work individually like
this; all of the constraints are considered and they care considered
equally important.
The second `foo` has additional constrains the first lacks. The
standard *does not care* what those constraints mean; what matters is
that it *has them*. Therefore, there is some set of types `T` which
the first one can be used with but not the second. Therefore, the
second is more constrained, and is preferred when applicable.
Received on 2023-05-07 15:35:07