Core/Misc: Port std::ranges::contains from c++23

This commit is contained in:
Shauren
2024-12-01 19:05:26 +01:00
parent 711fe685dd
commit 3e2abd2535
3 changed files with 31 additions and 2 deletions

View File

@@ -52,4 +52,32 @@ template <typename To, typename From,
#endif
}
// std::ranges::contains
#ifndef __cpp_lib_ranges_contains
#include <functional> // for std::ranges::equal_to, std::identity
#include <iterator> // for std::input_iterator, std::sentinel_for, std::projected
namespace advstd::ranges
{
struct Contains
{
template<std::input_iterator I, std::sentinel_for<I> S, class T, class Proj = std::identity>
requires std::indirect_binary_predicate<std::ranges::equal_to, std::projected<I, Proj>, T const*>
[[nodiscard]] inline constexpr bool operator()(I first, S last, T const& value, Proj proj = {}) const
{
return std::ranges::find(std::move(first), last, value, proj) != last;
}
template<std::ranges::input_range R, class T, class Proj = std::identity>
requires std::indirect_binary_predicate<std::ranges::equal_to, std::projected<std::ranges::iterator_t<R>, Proj>, T const*>
[[nodiscard]] inline constexpr bool operator()(R&& r, T const& value, Proj proj = {}) const
{
auto first = std::ranges::begin(r);
auto last = std::ranges::end(r);
return std::ranges::find(std::move(first), last, value, proj) != last;
}
} inline constexpr contains;
}
#endif
#endif

View File

@@ -709,7 +709,7 @@ void LootTemplate::ProcessPersonalLoot(std::unordered_map<Player*, std::unique_p
auto newEnd = std::remove_if(lootersForItem.begin(), lootersForItem.end(), [&](Player const* looter)
{
return std::ranges::find(gotLoot, looter) != gotLoot.end();
return advstd::ranges::contains(gotLoot, looter);
});
if (lootersForItem.begin() == newEnd)

View File

@@ -27,6 +27,7 @@
#include "Util.h"
#include "game_utilities_service.pb.h"
#include "RealmList.pb.h"
#include "advstd.h"
#include <boost/asio/ip/tcp.hpp>
#include <zlib.h>
@@ -129,7 +130,7 @@ void RealmList::UpdateRealms()
for (boost::asio::ip::tcp::endpoint const& endpoint : _resolver->ResolveAll(fields[2 + i].GetStringView(), ""))
{
boost::asio::ip::address address = endpoint.address();
if (std::ranges::find(addresses, address) != addresses.end())
if (advstd::ranges::contains(addresses, address))
continue;
addresses.push_back(std::move(address));