Suppose I have something like this:
template <typename T, typename ...args>
static std::map<T, std::tuple<args...>> MyMaps;
Every type is known on compile time. So for every configuration of types added to the map, a new map is created.
Is there a way to search in all instances of map that matches the T parameter with just the key (and the key type)?
EDIT: Sorry for super simplifying my question. I was afraid to make it too big and in the end it missed my intent. But I guess the what I was trying to achieve is impossible in the way I wanted as @Quimby explained.
What I really was trying to do was a debbug helper (actually to Unreal), to track object values something like this for a includable .h (debbughelper.h):
#include <tuple>
#include <vector>
#include <type_traits>
#define WATCHMYOBJECT(object, ...) //TO DO
#define RESCANMYOBJECT(object) //TO DO
template <typename ...T>
void Expand(T...args)
{
return;
}
template <typename T, typename ...args>
class MyWatcherClass
{
public:
static void WatchMyObject(T &object, args& ...b);
static void RescanMyObject(T& MyObject);
static std::vector<MyWatcherClass*> Instaces;
private:
std::tuple<args...> MyTuple = std::tuple<args...>();
std::vector<void*> VoidPointerStorage;
T* MyObjectPointer;
private:
MyWatcherClass();
~MyWatcherClass();
};
template <typename T, typename ...args>
void MyWatcherClass<T, args...>::WatchMyObject(T &MyObject, args& ...b)
{
MyWatcherClass<T, args...>* MyClassPointer = new MyWatcherClass;
InstacedObjects.push_back(MyClassPointer);
MyObjectPointer = &MyObject;
int helpint = 0;
MyClassPointer->MyTuple = std::make_tuple(b...);
Expand((MyClassPointer->PointerStorage.push_back((void*)&b),1)...);
}
template <typename T, typename ...args>
void MyWatcherClass<T, args...>::RescanMyObject(T &MyObject)
{
// I have yet to implement, but impossible to call this
// Compare Instaces[i].MyObjectPointer with &MyObject to find the matching one
// cast all the void pointers in std::vector<void*> VoidPointerStorage back to typed pointers using the tuple types
// Get the values derefing the pointers and update on the screen, log, etc
}
And then, with help of some macro magic, some one could do:
// #include <"debbughelper.h">
class MyNormalClass
{
public:
MyNormalClass(int _MyInt, float _MyFloat, std::string _MyString);
int MyInt;
float MyFloat;
std::string MyString;
};
MyNormalClass::MyNormalClass(int _MyInt, float _MyFloat, std::string _MyString) : MyInt(_MyInt), MyFloat(_MyFloat), MyString(_MyString)
{
}
int main()
{
MyNormalClass MyObject = MyNormalClass(1, 5.2f, std::string("hello"));
WATCHMYOBJECT(MyObject, MyObject.MyInt, MyObject.MyFloat, MyObject.MyString);
// do other stuff
RESCANMYOBJECT(MyObject); //easy, without the need to retype all the members
}
But there is no way to call RescanMyObject without the types of the members.