fork download
  1. #include <utility>
  2. #include <algorithm>
  3.  
  4. template<typename... Features>
  5. struct Foo : Features...
  6. {
  7. bool init()
  8. {
  9. typedef bool (Foo::*fptr)();
  10. auto il = {static_cast<fptr>(&Features::init)...};
  11. return std::all_of(il.begin(), il.end(), [&](fptr f){ return (this->*f)(); });
  12. }
  13. };
  14.  
  15. #include <iostream>
  16.  
  17. using namespace std;
  18.  
  19. struct A { bool init() { cout << "Hello " << endl; return true; } };
  20. struct B { bool init() { cout << "Template " << endl; return true; } };
  21. struct C { bool init() { cout << "World!" << endl; return true; } };
  22.  
  23. int main()
  24. {
  25. Foo<A, B, C> f;
  26. bool res = f.init(); // Prints "Hello Template World!"
  27. cout << res; // Prints 1
  28. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
Hello 
Template 
World!
1