1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-25 04:02:42 +01:00

Simplify umax

Add operator less and conversion operator.
This commit is contained in:
Nekotekina 2021-04-29 00:13:12 +03:00
parent b1736b6411
commit 5724d2d4c7
4 changed files with 11 additions and 27 deletions

View File

@ -138,7 +138,7 @@ bool cfg::try_to_uint64(u64* out, const std::string& value, u64 min, u64 max)
bool cfg::try_to_enum_value(u64* out, decltype(&fmt_class_string<int>::format) func, const std::string& value) bool cfg::try_to_enum_value(u64* out, decltype(&fmt_class_string<int>::format) func, const std::string& value)
{ {
u64 max = -1; u64 max = umax;
for (u64 i = 0;; i++) for (u64 i = 0;; i++)
{ {

View File

@ -530,7 +530,7 @@ static std::basic_string<u32> apply_modification(const patch_engine::patch_info&
auto ptr = dst + offset; auto ptr = dst + offset;
u32 resval = -1; u32 resval = umax;
switch (p.type) switch (p.type)
{ {

View File

@ -7,8 +7,6 @@
#include <algorithm> #include <algorithm>
#include "util/asm.hpp" #include "util/asm.hpp"
static const usz size_dropped = -1;
/* /*
C-style format parser. Appends formatted string to `out`, returns number of characters written. C-style format parser. Appends formatted string to `out`, returns number of characters written.
`out`: mutable reference to std::string, std::vector<char> or other compatible container `out`: mutable reference to std::string, std::vector<char> or other compatible container
@ -43,7 +41,7 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src)
const auto drop_sequence = [&] const auto drop_sequence = [&]
{ {
out.insert(out.end(), fmt - ctx.size, fmt); out.insert(out.end(), fmt - ctx.size, fmt);
ctx.size = size_dropped; ctx.size = umax;
}; };
const auto read_decimal = [&](uint result) -> uint const auto read_decimal = [&](uint result) -> uint
@ -143,7 +141,7 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src)
ctx = {0}; ctx = {0};
out.push_back(ch); out.push_back(ch);
} }
else if (ctx.size == size_dropped) else if (ctx.size == umax)
{ {
out.push_back(ch); out.push_back(ch);
} }
@ -694,7 +692,7 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src)
} }
// Handle unfinished sequence // Handle unfinished sequence
if (ctx.size && ctx.size != size_dropped) if (ctx.size && ctx.size != umax)
{ {
fmt--, drop_sequence(); fmt--, drop_sequence();
} }

View File

@ -480,39 +480,25 @@ struct get_int_impl<16>
}; };
// Return magic value for any unsigned type // Return magic value for any unsigned type
constexpr inline struct umax_helper constexpr struct umax_impl_t
{ {
constexpr umax_helper() noexcept = default;
template <typename T> requires (std::is_unsigned_v<std::common_type_t<T>>) || (std::is_same_v<std::common_type_t<T>, u128>) template <typename T> requires (std::is_unsigned_v<std::common_type_t<T>>) || (std::is_same_v<std::common_type_t<T>, u128>)
friend constexpr bool operator==(const umax_helper&, const T& rhs) constexpr bool operator==(const T& rhs) const
{ {
return rhs == static_cast<std::common_type_t<T>>(-1); return rhs == static_cast<std::common_type_t<T>>(-1);
} }
#if __cpp_impl_three_way_comparison >= 201711 && !__INTELLISENSE__
#else
template <typename T> requires (std::is_unsigned_v<std::common_type_t<T>>) || (std::is_same_v<std::common_type_t<T>, u128>) template <typename T> requires (std::is_unsigned_v<std::common_type_t<T>>) || (std::is_same_v<std::common_type_t<T>, u128>)
friend constexpr bool operator==(const T& lhs, const umax_helper&) constexpr bool operator<(const T& rhs) const
{ {
return lhs == static_cast<std::common_type_t<T>>(-1); return rhs < static_cast<std::common_type_t<T>>(-1);
}
#endif
#if __cpp_impl_three_way_comparison >= 201711
#else
template <typename T> requires (std::is_unsigned_v<std::common_type_t<T>>) || (std::is_same_v<std::common_type_t<T>, u128>)
friend constexpr bool operator!=(const umax_helper&, const T& rhs)
{
return rhs != static_cast<std::common_type_t<T>>(-1);
} }
template <typename T> requires (std::is_unsigned_v<std::common_type_t<T>>) || (std::is_same_v<std::common_type_t<T>, u128>) template <typename T> requires (std::is_unsigned_v<std::common_type_t<T>>) || (std::is_same_v<std::common_type_t<T>, u128>)
friend constexpr bool operator!=(const T& lhs, const umax_helper&) constexpr operator T() const
{ {
return lhs != static_cast<std::common_type_t<T>>(-1); return static_cast<std::common_type_t<T>>(-1);
} }
#endif
} umax; } umax;
enum class f16 : u16{}; enum class f16 : u16{};