// Boost.Varaint // Contains multivisitors that are implemented via variadic templates, std::tuple // and decltype(auto) // // See http://www.boost.org for most recent version, including documentation. // // Copyright Antony Polukhin, 2013-2014. // // Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). #ifndef BOOST_VARIANT_DETAIL_MULTIVISITORS_CPP14_BASED_HPP #define BOOST_VARIANT_DETAIL_MULTIVISITORS_CPP14_BASED_HPP #if defined(_MSC_VER) # pragma once #endif #include namespace boost { namespace detail { namespace variant { // Forward declaration template class one_by_one_visitor_and_value_referer_cpp14; template inline one_by_one_visitor_and_value_referer_cpp14 make_one_by_one_visitor_and_value_referer_cpp14( Visitor& visitor, Visitables visitables, std::tuple values ) { return one_by_one_visitor_and_value_referer_cpp14 ( visitor, visitables, values ); } template class one_by_one_visitor_and_value_referer_cpp14 { Visitor& visitor_; std::tuple values_; Visitables visitables_; public: // structors one_by_one_visitor_and_value_referer_cpp14( Visitor& visitor, Visitables visitables, std::tuple values ) BOOST_NOEXCEPT : visitor_(visitor) , values_(values) , visitables_(visitables) {} public: // visitor interfaces template decltype(auto) operator()(Value&& value) const { return ::boost::apply_visitor( make_one_by_one_visitor_and_value_referer_cpp14( visitor_, tuple_tail(visitables_), std::tuple_cat(values_, std::make_tuple(wrap::value>(value))) ) , unwrap(std::get<0>(visitables_)) // getting Head element ); } private: one_by_one_visitor_and_value_referer_cpp14& operator=(const one_by_one_visitor_and_value_referer_cpp14&); }; template class one_by_one_visitor_and_value_referer_cpp14, Values...> { Visitor& visitor_; std::tuple values_; public: one_by_one_visitor_and_value_referer_cpp14( Visitor& visitor, std::tuple<> /*visitables*/, std::tuple values ) BOOST_NOEXCEPT : visitor_(visitor) , values_(values) {} template decltype(auto) do_call(Tuple t, index_sequence) const { return visitor_(unwrap(std::get(t))...); } template decltype(auto) operator()(Value&& value) const { return do_call( std::tuple_cat(values_, std::make_tuple(wrap::value>(value))), make_index_sequence() ); } }; }} // namespace detail::variant template inline decltype(auto) apply_visitor(const Visitor& visitor, T1&& v1, T2&& v2, T3&& v3, TN&&... vn, typename boost::disable_if< boost::detail::variant::has_result_type >::type* = 0) { return boost::apply_visitor( ::boost::detail::variant::make_one_by_one_visitor_and_value_referer_cpp14( visitor, std::make_tuple( ::boost::detail::variant::wrap::value>(v2), ::boost::detail::variant::wrap::value>(v3), ::boost::detail::variant::wrap::value>(vn)... ), std::tuple<>() ), ::boost::forward(v1) ); } template inline decltype(auto) apply_visitor(Visitor& visitor, T1&& v1, T2&& v2, T3&& v3, TN&&... vn, typename boost::disable_if< boost::detail::variant::has_result_type >::type* = 0) { return ::boost::apply_visitor( ::boost::detail::variant::make_one_by_one_visitor_and_value_referer_cpp14( visitor, std::make_tuple( ::boost::detail::variant::wrap::value>(v2), ::boost::detail::variant::wrap::value>(v3), ::boost::detail::variant::wrap::value>(vn)... ), std::tuple<>() ), ::boost::forward(v1) ); } } // namespace boost #endif // BOOST_VARIANT_DETAIL_MULTIVISITORS_CPP14_BASED_HPP