Skip to content

Instantly share code, notes, and snippets.

@seivan
Created September 22, 2018 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seivan/1f1c2ec8ecc81a7d908cbf73aa959614 to your computer and use it in GitHub Desktop.
Save seivan/1f1c2ec8ecc81a7d908cbf73aa959614 to your computer and use it in GitHub Desktop.
N variadic tuple
#include <iostream>
#include <string>
#include <type_traits>
class Frombler {
public:
virtual void fromble() = 0;
};
class Foo : public Frombler {
public:
void fromble() {
std::cout << "Foo Foo" << std::endl;
}
};
class Bar : public Frombler {
public:
explicit Bar(const std::string& t)
: text(t)
{
}
void fromble() {
std::cout << "Bar " << text << std::endl;
}
private:
std::string text;
};
template <typename T>
class Generator {
public:
Generator() {
static_assert(std::is_base_of<Frombler, T>::value, "T is not derived from Frombler");
}
};
template <typename T, class... Mixins>
class ConcreteGenerator: public Generator<T> {
public:
ConcreteGenerator()
: Generator<T>() {
}
T makeMember(const Mixins&... mixins) {
return T(mixins...);
}
};
int main() {
auto foo = ConcreteGenerator<Foo>();
auto bar = ConcreteGenerator<Bar, std::string>();
Foo f1 = foo.makeMember();
f1.fromble();
Bar b1 = bar.makeMember("lolz");
b1.fromble();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment