Boost logo

Boost :

Subject: [boost] Small contribution to algorithm library: clamp function
From: Тимофей Игнатьич (fhq_at_[hidden])
Date: 2011-02-23 02:54:10


I wasn't able to find a clamp function in boost so i submitted my version for discussion and refinement here:
http://www.boostpro.com/vault/index.php?&direction=0&order=&directory=Algorithms (file clamp.hpp)

Summary:
    clamp(a, x, b)
        Effect:
            if (x < a) returns a, otherwise if (b < x) returns b, otherwise returns x.

    clamp(a, x, b, comp)
    clamp<comp>(a, x, b)
        Effect:
            if comp(x, a) returns a, otherwise if comp(b, x) returns b, otherwise returns x.

Let me know what you think. Maybe i was wrong and such function does already exist within boost?


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