feat add clamp
All checks were successful
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m0s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m7s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m12s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m12s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m13s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (pull_request) Successful in 1m2s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m38s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (pull_request) Successful in 59s
linux-x64-gcc / linux-gcc (push) Successful in 1m53s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (pull_request) Successful in 1m2s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (pull_request) Successful in 1m13s
linux-hisiv500-gcc / linux-gcc-hisiv500 (pull_request) Successful in 1m24s
linux-mips64-gcc / linux-gcc-mips64el (pull_request) Successful in 1m28s
linux-x64-gcc / linux-gcc (pull_request) Successful in 1m52s

This commit is contained in:
tqcq 2024-01-12 15:26:11 +08:00
parent 1610953cd8
commit af72a33e68

22
src/ulib/utils/utils.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef ULIB_SRC_ULIB_UTILS_UTILS_H_
#define ULIB_SRC_ULIB_UTILS_UTILS_H_
#include <functional>
namespace ulib {
template<typename T>
const T &
Clamp(const T &value, const T &low, const T &high)
{
return Clamp(value, low, high, std::less<T>{});
}
template<typename T, typename Comp>
const T &
Clamp(const T &value, const T &low, const T &high, Comp comp)
{
return comp(value, low) ? low : (comp(high, value) ? high : value);
}
}// namespace ulib
#endif// ULIB_SRC_ULIB_UTILS_UTILS_H_