I'm struggling with multiple inheritance with variadic templates.
This is my code so far:
template <typename U>
class id_map {
public:
std::vector<U> vec_;
};
now I want to initialize another class, which inherits multiple times from id_map, something like this:
template<typename ... T>
class constant_allkey_map : public id_map<T> ... {
private:
public:
template <typename U>
void push_back(U i) {
id_map<U>::vec_.push_back(i);
}
};
This works and I can access it just fine:
constant_allkey_map<int, long> cakm;
cakm.push_back<int>(1);
It fails when I try something like this:
constant_allkey_map<int, int> cakm;
with error
"duplicate base type id_map<int> invalid".
I did some reading and it seems I'm supposed to extend id_map templates with id parameter:
template <size_t i_, typename U>
class id_map ...
but I'm not sure how to pass that id in in inheritance part:
template<typename ... T>
class constant_allkey_map : public id_map<T> ... {
Can someone please help me? Of if I'm doing this entirely wrong, point me in the right direction?
cakm.push_back(1);
to do whencakm
isconstant_allkey_map<int,int>
?