Merge pull request 'feat add clamp' (#5) from feat/add_clamp into develop
All checks were successful
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m2s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 57s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m1s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m7s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m12s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m26s
linux-x64-gcc / linux-gcc (push) Successful in 1m51s
All checks were successful
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m2s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 57s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m1s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m7s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m12s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m26s
linux-x64-gcc / linux-gcc (push) Successful in 1m51s
Reviewed-on: #5
This commit is contained in:
commit
5f4384e173
22
src/ulib/utils/utils.h
Normal file
22
src/ulib/utils/utils.h
Normal 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_
|
Loading…
Reference in New Issue
Block a user