mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-15 23:20:36 +01:00
Core/Misc: Port std::ranges::contains from c++23
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user