From 78942ce21d75889279e1ebd13804225e098310ca Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 3 Feb 2022 00:22:37 -0600 Subject: [PATCH] [ox/std] Add ox::clamp --- deps/ox/src/ox/std/math.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/deps/ox/src/ox/std/math.hpp b/deps/ox/src/ox/std/math.hpp index 57a8ea7f..28f77ec7 100644 --- a/deps/ox/src/ox/std/math.hpp +++ b/deps/ox/src/ox/std/math.hpp @@ -24,6 +24,12 @@ constexpr const T &max(const T &a, const T &b) noexcept { return a > b ? a : b; } +template +[[nodiscard]] +constexpr const T &clamp(const T &v, const T &lo, const T &hi) noexcept { + return min(ox::max(v, lo), hi); +} + template [[nodiscard]] constexpr I pow(I v, int e) noexcept {