I am using something like:
struct VectorCache { template<typename T> std::vector<T>& GetTs() { static std::vector<T> ts; return ts; } };
to create / access some vectors based on the specified type. This works fine as long as I only have one object of type VectorCache , but when I use multiple objects, I get the same vectors from all instances of VectorCache , since the vectors are static variables.
I tried moving vectors as member variables using something similar to boost::any and accessing them using std::type_index for T, but it was somehow slower than the direct access I used before.
Other options are converting the struct VectorCache to something like template<int index> struct VectorCache , but the problem still exists - I need to be careful to have only one instance / index in order to have the correct behavior.
Is it possible to access vectors directly based on T , and also use a caching instance instead of a class?
source share