// Extend Boost.Variant library with ternary visitations. // // Copyright (c) 2005 // Shayne Fletcher //----------------------------------------------------------------------------- // boost variant/detail/apply_visitor_binary.hpp header file // See http://www.boost.org for updates, documentation, and revision history. //----------------------------------------------------------------------------- // // Copyright (c) 2002-2003 // Eric Friedman // // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without fee, // provided that the above copyright notice appears in all copies and // that both the copyright notice and this permission notice appear in // supporting documentation. No representations are made about the // suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. #if !defined(APPLY_VISITOR_TERNARY_BB82733D_94CE_4A23_A6DE_BDF0EDBB5FA7_INCLUDED) # define APPLY_VISITOR_TERNARY_BB82733D_94CE_4A23_A6DE_BDF0EDBB5FA7_INCLUDED # if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once # endif // defined(_MSC_VER) && (_MSC_VER >= 1020) # include namespace boost { namespace detail { namespace variant { template class apply_visitor_ternary_invoke { public: typedef typename VisitorT::result_type result_type; apply_visitor_ternary_invoke(VisitorT& visitor, Value1T& value1) : visitor_(visitor), value1_(value1) { } template BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type) operator()(Value2T& value2, Value3T& value3) { return visitor_(value1_, value2, value3); } private: VisitorT& visitor_; Value1T& value1_; }; template class apply_visitor_ternary_unwrap { public: typedef typename VisitorT::result_type result_type; apply_visitor_ternary_unwrap(VisitorT& visitor , Visitable2T& visitable2, Visitable3T& visitable3) : visitor_(visitor), visitable2_(visitable2), visitable3_(visitable3) { } template BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type) operator()(Value1T& value1) { apply_visitor_ternary_invoke< VisitorT, Value1T> invoker(visitor_, value1); return boost::apply_visitor(invoker, visitable2_, visitable3_); } private: VisitorT& visitor_; Visitable2T& visitable2_; Visitable3T& visitable3_; }; }} // namespace detail::variant # if !BOOST_WORKAROUND(__EDG__, BOOST_TESTED_AT(302)) # define BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(V) \ BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename V::result_type) \ /**/ # else // EDG-based compilers # define BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(V) \ typename enable_if< \ mpl::not_< is_const< V > > \ , BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename V::result_type) \ >::type \ /**/ # endif // EDG-based compilers workaround template inline BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE(VisitorT) apply_visitor(VisitorT& visitor , Visitable1T& visitable1, Visitable2T& visitable2, Visitable3T& visitable3) { ::boost::detail::variant::apply_visitor_ternary_unwrap< VisitorT, Visitable2T, Visitable3T> unwrapper( visitor, visitable2, visitable3); return boost::apply_visitor(unwrapper, visitable1); } # undef BOOST_VARIANT_AUX_APPLY_VISITOR_NON_CONST_RESULT_TYPE // const visitor version # if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) template inline BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(typename VisitorT::result_type) apply_visitor(VisitorT const& visitor , Visitable1T& visitable1, Visitable2T& visitable2, Visitable3T& visitable3) { ::boost::detail::variant::apply_visitor_ternary_unwrap< VisitorT const, Visitable2T, Visitable3T> unwrapper( visitor, visitable2, visitable3); return boost::apply_visitor(unwrapper, visitable1); } # endif // !BOOST_WORKAROUND(BOOST_MSVC, <= 1300) } // namespace boost #endif // !defined(APPLY_VISITOR_TERNARY_BB82733D_94CE_4A23_A6DE_BDF0EDBB5FA7_INCLUDED)