Created
September 22, 2018 19:55
-
-
Save seivan/1f1c2ec8ecc81a7d908cbf73aa959614 to your computer and use it in GitHub Desktop.
N variadic tuple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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