|
Boost : |
Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: Thomas Klimpel (Thomas.Klimpel_at_[hidden])
Date: 2011-09-25 06:57:42
Jeffrey Lee Hellrung, Jr. wrote:
> Stated differently, I would think that the existence of an operator< comparing
> objects of different types implies (more often than not) an ordering between
> objects of those types. And if a user implicitly requests the use of this
> operator< through a call to clamp, I don't see why the interface should
> prohibit that.
I'm quite happy with the behavior of std::max to only accept arguments of the same type, because it prevents bugs like the following:
for (std::size_t i = v.size()-1; i > -1; --i) { ... }
This bug also provides a counterexample to your statement that the existence of an operator< accepting the arguments is enough for assuming that it does the right thing. IMO, there are very good reasons why std::max is defined the way it is, and clamp should better follow the precedence of std::max instead of exhibiting unexpected behavior.
Regards,
Thomas
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk