From c49738e7a398ecb2364fe8af846c50d9a06999d5 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 16 Aug 2017 17:26:16 +1000 Subject: [PATCH] coord/ops: add elementwise limit operation --- coord/ops.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/coord/ops.hpp b/coord/ops.hpp index fe275f51..ba70e257 100644 --- a/coord/ops.hpp +++ b/coord/ops.hpp @@ -703,6 +703,25 @@ namespace util { } + //------------------------------------------------------------------------- + + template < + size_t S, + typename T, + template class K, + typename = std::enable_if_t< + is_coord_v>, void + > + > + constexpr + K + limit (K k, K lo, K hi) + { + assert (all (lo <= hi)); + return max (min (k, hi), lo); + } + + ///------------------------------------------------------------------------ template < size_t S,