Core/Misc: Allow all kinds of non-map containers in grid searchers

This commit is contained in:
Shauren
2020-09-04 18:34:36 +02:00
parent 600a6b5f68
commit a02d36f18c

View File

@@ -191,26 +191,27 @@ namespace Trinity
// Generic base class to insert elements into arbitrary containers using push_back
template<typename Type>
class ContainerInserter {
class ContainerInserter
{
using InserterType = void(*)(void*, Type&&);
void* ref;
InserterType inserter;
// MSVC workaround
template<typename T>
static void InserterOf(void* ref, Type&& type)
{
static_cast<T*>(ref)->push_back(std::move(type));
}
protected:
template<typename T>
ContainerInserter(T& ref_) : ref(&ref_), inserter(&InserterOf<T>) { }
void Insert(Type type)
ContainerInserter(T& ref_) : ref(&ref_)
{
inserter(ref, std::move(type));
inserter = [](void* containerRaw, Type&& object)
{
T* container = reinterpret_cast<T*>(containerRaw);
container->insert(container->end(), std::move(object));
};
}
void Insert(Type object)
{
inserter(ref, std::move(object));
}
};