Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:06

0001 /*!
0002 @file
0003 Defines `boost::hana::tap`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_TAP_HPP
0011 #define BOOST_HANA_TAP_HPP
0012 
0013 #include <boost/hana/fwd/tap.hpp>
0014 
0015 #include <boost/hana/concept/monad.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/functional/partial.hpp>
0019 #include <boost/hana/lift.hpp>
0020 
0021 
0022 namespace boost { namespace hana {
0023     //! @cond
0024     template <typename M>
0025     template <typename F>
0026     constexpr auto tap_t<M>::operator()(F&& f) const {
0027     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0028         static_assert(hana::Monad<M>::value,
0029         "hana::tap<M> requires 'M' to be a Monad");
0030     #endif
0031 
0032         using Tap = BOOST_HANA_DISPATCH_IF(tap_impl<M>,
0033             hana::Monad<M>::value
0034         );
0035 
0036         return Tap::apply(static_cast<F&&>(f));
0037     }
0038     //! @endcond
0039 
0040     namespace detail {
0041         template <typename M>
0042         struct tap_helper {
0043             template <typename F, typename X>
0044             constexpr auto operator()(F&& f, X&& x) const {
0045                 (void)static_cast<F&&>(f)(x);
0046                 return hana::lift<M>(static_cast<X&&>(x));
0047             }
0048         };
0049     }
0050 
0051     template <typename M, bool condition>
0052     struct tap_impl<M, when<condition>> : default_ {
0053         template <typename F>
0054         static constexpr auto apply(F&& f)
0055         { return hana::partial(detail::tap_helper<M>{}, static_cast<F&&>(f)); }
0056     };
0057 }} // end namespace boost::hana
0058 
0059 #endif // !BOOST_HANA_TAP_HPP