// -*-c++-*- // vim: set ft=cpp: /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ #pragma once #include // IWYU pragma: export #include namespace cm { #if __cplusplus >= 201703L || defined(_MSVC_LANG) && _MSVC_LANG >= 201703L using std::clamp; #else template T const& clamp(T const& v, T const& lo, T const& hi) { assert(!(hi < lo)); return (v < lo) ? lo : (hi < v) ? hi : v; } template T const& clamp(T const& v, T const& lo, T const& hi, Comp comp) { assert(!comp(hi, lo)); return comp(v, lo) ? lo : comp(hi, v) ? hi : v; } #endif } // namespace cm