Hi!
I was surprised to find that I cannot use libc++'s `std::max(a, b)` if `a<b`
yields an object with an explicit operator bool. Is that intended, or should
I file a bug?
It seems to work for libstdc++. It also works if I use `std::max(a, b, cmp)`
and the result of `cmp(a, b)` has an explicit operator bool.
Full example <https://godbolt.org/g/cTqgvz>:
Hi Jö,
I was surprised to find that I cannot use libc++'s `std::max(a, b)` if `a<b`
yields an object with an explicit operator bool. Is that intended, or should
I file a bug?
std::max is defined to work on types that are "LessThanComparable",
which in turn requires the result of "a < b" to be *implicitly*
convertible to bool
(C++ named requirements: LessThanComparable - cppreference.com). An
"explicit operator bool" (fairly unsurprisingly) doesn't qualify.
Cheers.
Tim.
To answer my own question: apparently this is due to the still open issue 2114
<https://cplusplus.github.io/LWG/issue2114> in the standard. The proposed
resolution is to require `a<b` to be _both_ contextually and and implicitly
convertible to bool, plus a few other things related to short-circuiting.
Regards,
Jö.