I would like to have a container that can ingest an object, and store different parts of it into different internal containers.
Something like this:
// Pseudo-code
template<typename A, typename B, typename C>
class Container {
std::vector<B> vb;
std::vector<C> vc;
public:
void push_back(const A &a) {
vb.push_back(a);
vc.push_back(a);
}
};
class AA {
int a;
std::string s;
};
class BB {
int a;
};
class CC {
std::string s;
};
Container<AA, BB, CC> cont;
AA aa;
cont.push_back(aa);
I would like object vb
to get what is in common between classes A an B (slicing), and the same for object vc
.
Ideally, classes AA, BB and CC should not be in a hierarchical relation. I would like the compiler to be able to match the members by their type.
I would prefer a solution with small performance penalties.