[ox/std] Make ox::min/max use values instead of refs for integrals, add CommonRefWith
This commit is contained in:
parent
5de5eee215
commit
eb55144211
6
deps/ox/src/ox/std/concepts.hpp
vendored
6
deps/ox/src/ox/std/concepts.hpp
vendored
@ -16,6 +16,10 @@ template<typename T, typename U>
|
|||||||
concept CommonPtrWith = ox::is_same_v<typename ox::remove_pointer<const T*>::type,
|
concept CommonPtrWith = ox::is_same_v<typename ox::remove_pointer<const T*>::type,
|
||||||
typename ox::remove_pointer<const U*>::type>;
|
typename ox::remove_pointer<const U*>::type>;
|
||||||
|
|
||||||
|
template<typename T, typename U>
|
||||||
|
concept CommonRefWith = ox::is_same_v<typename ox::remove_reference_t<const T&>,
|
||||||
|
typename ox::remove_reference_t<const U&>>;
|
||||||
|
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
concept same_as = ox::is_same_v<T, T>;
|
concept same_as = ox::is_same_v<T, T>;
|
||||||
|
|
||||||
@ -50,4 +54,4 @@ constexpr auto isOxString(const StringView*) noexcept {
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept OxString_c = detail::isOxString(static_cast<T*>(nullptr));
|
concept OxString_c = detail::isOxString(static_cast<T*>(nullptr));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
24
deps/ox/src/ox/std/math.hpp
vendored
24
deps/ox/src/ox/std/math.hpp
vendored
@ -14,19 +14,37 @@ namespace ox {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr const T &min(const T &a, const T &b) noexcept {
|
constexpr T min(T a, T b) noexcept requires(ox::is_integral_v<T>) {
|
||||||
return a < b ? a : b;
|
return a < b ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr const T &max(const T &a, const T &b) noexcept {
|
constexpr const T &min(const T &a, const T &b) noexcept requires(!ox::is_integral_v<T>) {
|
||||||
|
return a < b ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr T max(T a, T b) noexcept requires(ox::is_integral_v<T>) {
|
||||||
return a > b ? a : b;
|
return a > b ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr const T &clamp(const T &v, const T &lo, const T &hi) noexcept {
|
constexpr const T &max(const T &a, const T &b) noexcept requires(!ox::is_integral_v<T>) {
|
||||||
|
return a > b ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr T clamp(T v, T lo, T hi) noexcept requires(ox::is_integral_v<T>) {
|
||||||
|
return min(ox::max(v, lo), hi);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr const T &clamp(const T &v, const T &lo, const T &hi) noexcept requires(!ox::is_integral_v<T>) {
|
||||||
return min(ox::max(v, lo), hi);
|
return min(ox::max(v, lo), hi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user