29.11.2013 22:31, Sumant Tambe:
template <class Poly> void test_poly(Poly& p) { match(p)( [](int i) { std::cout << "int = " << i << "\n"; }, [](double d) { std::cout << "double = " << d << "\n"; }, [](const std::string &s) { std::cout << "string = " << s << "\n"; }, [](std::ostream &o) { std::cout << "found ostream" << "\n"; } ); }
Just for your information, there is Boost.Functional/OverloadedFunction library - http://www.boost.org/doc/libs/1_55_0/libs/functional/overloaded_function/doc... It has make_overloaded_function template function http://www.boost.org/doc/libs/1_55_0/libs/functional/overloaded_function/doc... - which is somewhat similar (not sure if it provides required typedef for result_type). -- Evgeny Panasyuk