#ifndef BOOST_VARIANT_MATCH_HPP #define BOOST_VARIANT_MATCH_HPP #include #include #include namespace boost { namespace detail { template struct variant_matcher; template struct variant_matcher { template static auto match(V && v, F && f) -> decltype(f(boost::get(std::forward(v)))) { return f(boost::get(std::forward(v))); } }; template struct variant_matcher { template static auto match(V && v, F f, Fs... fs) -> typename std::common_type< decltype(f(boost::get(v))), decltype(variant_matcher::match(v, std::forward(fs)...)) >::type { if (auto * const p = boost::get(&v)) // (if only we had N4127!) return f(*p); else return variant_matcher::match(v, std::forward(fs)...); } }; } template auto match(variant & v, F && ... f) -> decltype(detail::variant_matcher::template match(v, std::forward(f)...)) { return detail::variant_matcher::template match(v, std::forward(f)...); } template auto match(variant const & v, F && ... f) -> decltype(detail::variant_matcher::template match(v, std::forward(f)...)) { return detail::variant_matcher::template match(v, std::forward(f)...); } } #endif