Skip to content

Instantly share code, notes, and snippets.

@seivan seivan/world.cpp
Created Sep 22, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.