Merge cc5eb6c410
into 6c1cee5f79
This commit is contained in:
commit
69af527f9c
|
@ -18,7 +18,6 @@
|
|||
#include <locale>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <stdexcept> // std::runtime_error
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
@ -540,7 +539,7 @@ std::string tr_strpercent(double x)
|
|||
return fmt::format("{:.0Lf}", x);
|
||||
}
|
||||
|
||||
std::string tr_strratio(double ratio, char const* infinity)
|
||||
std::string tr_strratio(double ratio, std::string_view infinity)
|
||||
{
|
||||
if ((int)ratio == TR_RATIO_NA)
|
||||
{
|
||||
|
@ -549,7 +548,7 @@ std::string tr_strratio(double ratio, char const* infinity)
|
|||
|
||||
if ((int)ratio == TR_RATIO_INF)
|
||||
{
|
||||
return infinity != nullptr ? infinity : "";
|
||||
return std::string{ infinity };
|
||||
}
|
||||
|
||||
return tr_strpercent(ratio);
|
||||
|
|
|
@ -251,7 +251,7 @@ template<typename T, std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
|
|||
|
||||
/** @param ratio the ratio to convert to a string
|
||||
@param infinity the string representation of "infinity" */
|
||||
[[nodiscard]] std::string tr_strratio(double ratio, char const* infinity);
|
||||
[[nodiscard]] std::string tr_strratio(double ratio, std::string_view infinity);
|
||||
|
||||
// ---
|
||||
|
||||
|
|
|
@ -76,8 +76,7 @@ template<typename T>
|
|||
|
||||
if (auto* const map = var != nullptr ? var->get_if<tr_variant::MapIndex>() : nullptr; map != nullptr)
|
||||
{
|
||||
map->erase(key);
|
||||
return &map->try_emplace(key, std::forward<T>(val)).first;
|
||||
return &map->insert_or_assign(key, std::forward<T>(val)).first;
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
|
@ -148,8 +148,26 @@ public:
|
|||
return { vec_.emplace_back(key, tr_variant{ std::forward<Val>(val) }).second, true };
|
||||
}
|
||||
|
||||
template<typename Val>
|
||||
std::pair<tr_variant&, bool> insert_or_assign(tr_quark const key, Val&& val)
|
||||
{
|
||||
auto res = try_emplace(key, std::forward<Val>(val));
|
||||
if (!res.second)
|
||||
{
|
||||
res.first = std::forward<Val>(val);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// --- custom functions
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] TR_CONSTEXPR20 auto find_if(tr_quark const key) noexcept
|
||||
{
|
||||
auto const iter = find(key);
|
||||
return iter != end() ? iter->second.get_if<Type>() : nullptr;
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] TR_CONSTEXPR20 auto find_if(tr_quark const key) const noexcept
|
||||
{
|
||||
|
|
3298
utils/remote.cc
3298
utils/remote.cc
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue