I am trying to create a class thats going to draw elements from a set of vectors (and also hold these vectors as containers inside the class), but i feel that when managing
having lots of functions like vectorOneAdd, vectorTwoAdd used in order to add elements to the vector is pointless. There must be a better way
There is:
class Cookie {
std::vector chocolateContainer;
std::vector sugarContainer;
private:
template
std::vector& get_vector(const T&); // not implemented but particularized
// write one of these for each vector:
template<>
std::vector& get_vector(const Chocolate&) { return chocolateVector; }
template<>
std::vector& get_vector(const Sugar&) { return sugarVector; }
public:
template
void add(T element) {
auto& v = get_vector(element);
v.push_back(std::move(element));
}
};