Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:32

0001 //-----------------------------------------------------------------------------
0002 // boost variant/detail/apply_visitor_unary.hpp header file
0003 // See http://www.boost.org for updates, documentation, and revision history.
0004 //-----------------------------------------------------------------------------
0005 //
0006 // Copyright (c) 2002-2003 Eric Friedman
0007 // Copyright (c) 2014-2023 Antony Polukhin
0008 //
0009 // Distributed under the Boost Software License, Version 1.0. (See
0010 // accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
0012 
0013 #ifndef BOOST_VARIANT_DETAIL_APPLY_VISITOR_UNARY_HPP
0014 #define BOOST_VARIANT_DETAIL_APPLY_VISITOR_UNARY_HPP
0015 
0016 #include <boost/config.hpp>
0017 #include <utility>
0018 
0019 #if !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
0020 #   include <boost/mpl/distance.hpp>
0021 #   include <boost/mpl/advance.hpp>
0022 #   include <boost/mpl/deref.hpp>
0023 #   include <boost/mpl/size.hpp>
0024 #   include <boost/utility/declval.hpp>
0025 #   include <boost/core/enable_if.hpp>
0026 #   include <boost/type_traits/copy_cv_ref.hpp>
0027 #   include <boost/type_traits/remove_reference.hpp>
0028 #   include <boost/variant/detail/has_result_type.hpp>
0029 #endif
0030 
0031 namespace boost {
0032 
0033 //////////////////////////////////////////////////////////////////////////
0034 // function template apply_visitor(visitor, visitable)
0035 //
0036 // Visits visitable with visitor.
0037 //
0038 
0039 //
0040 // nonconst-visitor version:
0041 //
0042 
0043 template <typename Visitor, typename Visitable>
0044 inline typename Visitor::result_type
0045 apply_visitor(Visitor& visitor, Visitable&& visitable)
0046 {
0047     return std::forward<Visitable>(visitable).apply_visitor(visitor);
0048 }
0049 
0050 //
0051 // const-visitor version:
0052 //
0053 
0054 template <typename Visitor, typename Visitable>
0055 inline typename Visitor::result_type
0056 apply_visitor(const Visitor& visitor, Visitable&& visitable)
0057 {
0058     return std::forward<Visitable>(visitable).apply_visitor(visitor);
0059 }
0060 
0061 
0062 #if !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
0063 #define BOOST_VARIANT_HAS_DECLTYPE_APPLY_VISITOR_RETURN_TYPE
0064 
0065 // C++14
0066 namespace detail { namespace variant {
0067 
0068 // This class serves only metaprogramming purposes. none of its methods must be called at runtime!
0069 template <class Visitor, class Variant>
0070 struct result_multideduce1 {
0071     typedef typename remove_reference<Variant>::type::types types;
0072     typedef typename boost::mpl::begin<types>::type begin_it;
0073     typedef typename boost::mpl::advance<
0074         begin_it, boost::mpl::int_<boost::mpl::size<types>::type::value - 1>
0075     >::type                                         last_it;
0076 
0077     template <class It, class Dummy = void> // avoid explicit specialization in class scope
0078     struct deduce_impl {
0079         typedef typename boost::mpl::next<It>::type next_t;
0080         typedef typename boost::mpl::deref<It>::type value_t;
0081         typedef decltype(true ? boost::declval< Visitor& >()( boost::declval< copy_cv_ref_t< value_t, Variant > >() )
0082                               : boost::declval< typename deduce_impl<next_t>::type >()) type;
0083     };
0084 
0085     template <class Dummy>
0086     struct deduce_impl<last_it, Dummy> {
0087         typedef typename boost::mpl::deref<last_it>::type value_t;
0088         typedef decltype(boost::declval< Visitor& >()( boost::declval< copy_cv_ref_t< value_t, Variant > >() )) type;
0089     };
0090 
0091     typedef typename deduce_impl<begin_it>::type type;
0092 };
0093 
0094 template <class Visitor, class Variant>
0095 struct result_wrapper1
0096 {
0097     typedef typename result_multideduce1<Visitor, Variant>::type result_type;
0098 
0099     Visitor&& visitor_;
0100     explicit result_wrapper1(Visitor&& visitor) BOOST_NOEXCEPT
0101         : visitor_(std::forward<Visitor>(visitor))
0102     {}
0103 
0104     template <class T>
0105     result_type operator()(T&& val) const {
0106         return visitor_(std::forward<T>(val));
0107     }
0108 };
0109 
0110 }} // namespace detail::variant
0111 
0112 template <typename Visitor, typename Visitable>
0113 inline decltype(auto) apply_visitor(Visitor&& visitor, Visitable&& visitable,
0114     typename boost::disable_if<
0115         boost::detail::variant::has_result_type<Visitor>,
0116         bool
0117     >::type = true)
0118 {
0119     boost::detail::variant::result_wrapper1<Visitor, Visitable> cpp14_vis(std::forward<Visitor>(visitor));
0120     return std::forward<Visitable>(visitable).apply_visitor(cpp14_vis);
0121 }
0122 
0123 #endif // !defined(BOOST_NO_CXX14_DECLTYPE_AUTO) && !defined(BOOST_NO_CXX11_DECLTYPE_N3276)
0124 
0125 } // namespace boost
0126 
0127 #endif // BOOST_VARIANT_DETAIL_APPLY_VISITOR_UNARY_HPP