Re:The joy of max()
by mehrdadn on Friday March 30, 2018 @09:14PM
(#16721077)
Edit: apologies, I'm blind; never mind. I thought I double-checked but the use of > instead of < tripped me up.
[ Parent
| on HN ]
Stepanov disagrees. You should return the second parameter if a, b are equivalent (and you should use < anyway):
template<typename T>
inline constexpr const T& max(const T& a, const T& b) {
return (b < a ? a : b);
}What’s the reasoning behind this?
I think to be comparable in c++ types are required to implement < operator and the same is exclusively used by the stdlib.