feat(Core/Containers): MapGetValuePtr (#6111)
* feat(Core/Containers): MapGetValuePtr * Added MapGetValuePtr to allow writing `if (Val* v = MapGetValuePtr(map, key))` (cherry picked from commit https://github.com/TrinityCore/TrinityCore/commit/a1e3b54e076bf0361d23ace53703a4e501354d7c) Co-Authored-By: Shauren <shauren.trinity@gmail.com>
This commit is contained in:
@@ -165,6 +165,16 @@ namespace acore::Containers
|
|||||||
return SelectRandomWeightedContainerElement(container, weights);
|
return SelectRandomWeightedContainerElement(container, weights);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pointer to mapped value (or the value itself if map stores pointers)
|
||||||
|
*/
|
||||||
|
template<class M>
|
||||||
|
inline auto MapGetValuePtr(M& map, typename M::key_type const& key) -> decltype(AddressOrSelf(map.find(key)->second))
|
||||||
|
{
|
||||||
|
auto itr = map.find(key);
|
||||||
|
return itr != map.end() ? AddressOrSelf(itr->second) : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @fn void acore::Containers::RandomShuffle(C& container)
|
* @fn void acore::Containers::RandomShuffle(C& container)
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user