fork download
  1. template<typename T, class...Fs> struct visitor_t;
  2.  
  3. template<typename T, class F1, class...Fs>
  4. struct visitor_t<T, F1, Fs...> : F1, visitor_t<T, Fs...>::type {
  5. typedef visitor_t type;
  6. visitor_t(F1 head, Fs...tail) : F1(head), visitor_t<T, Fs...>::type(tail...) {}
  7.  
  8. using F1::operator();
  9. using visitor_t<T, Fs...>::type::operator();
  10. };
  11.  
  12. template<typename T, class F> struct visitor_t<T, F> : F, boost::static_visitor<T> {
  13. typedef visitor_t type;
  14. visitor_t(F f) : F(f) {}
  15. using F::operator();
  16. };
  17.  
  18. template<typename T=void, class...Fs>
  19. typename visitor_t<T, Fs...>::type make_visitor(Fs...x) { return {x...}; }
  20.  
  21. struct Person
  22. {
  23. std::string name;
  24. double height, weight;
  25. friend std::ostream& operator<<(std::ostream& os, Person const& s) {
  26. return os << "Person { name:" << s.name << ", height:" << s.height << ", weight:" << s.weight << " }";
  27. }
  28. };
  29.  
  30.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty