Boost logo

Boost :

Subject: Re: [boost] Boost.Algorithm design question
From: Stephan T. Lavavej (stl_at_[hidden])
Date: 2011-10-06 21:42:21


[Phil Endecott]
> My argument was that for trivial things we actually have the
> implementation in our minds first and then find ourselves trying to
> think of some other way of expressing the same thing in order to write
> down a spec; in the process, we're as likely to make a mistake in the
> spec as we are to make a mistake in the implementation. Examples:
> clamp(val,lo,hi) = val<lo ? lo : val>hi : hi : val;
> vs.
> clamp(val,lo,hi) returns the middle value when (val,lo,hi) are
> ordered according to operator<

[Dave Abrahams]
> Wow, that certainly is stark. When I try to describe it better in
> words, it reads just like your implementation. But I'm not sure what
> that proves.

Amusingly (to me, at least), the implementation is incorrect. It says val > hi instead of hi < val.

STL


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk