There is a templated class, let it be
template class A { std::vector data; };
The problem I am facing here is,
std::any
is the modern c++17 solution. Specifically, you should use
A a;
a.data.push_back(0);
// fill refernces...
std::vector refernces;
refernces.push_back(&a.data[0]);
// check which type is active.
if(int** iPtr = std::any_cast(&references[0]); iPtr != nullptr)
{
// its an int*
int& i = **iPtr;
// do something with i.
}
These pointers can point into the A
and A
vectors.
For a complete reference, see here https://en.cppreference.com/w/cpp/utility/any.