3 Defines `boost::hana::tap`.
5 @copyright Louis Dionne 2013-2016
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_TAP_HPP
11 #define BOOST_HANA_TAP_HPP
13 #include <boost/hana/fwd/tap.hpp>
15 #include <boost/hana/concept/monad.hpp>
16 #include <boost/hana/config.hpp>
17 #include <boost/hana/core/dispatch.hpp>
18 #include <boost/hana/functional/partial.hpp>
19 #include <boost/hana/lift.hpp>
22 BOOST_HANA_NAMESPACE_BEGIN
25 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
26 static_assert(hana::Monad<M>::value,
27 "hana::tap<M> requires 'M' to be a Monad");
31 constexpr auto operator()(F&& f) const {
32 using Tap = BOOST_HANA_DISPATCH_IF(tap_impl<M>,
36 return Tap::apply(static_cast<F&&>(f));
43 template <typename F, typename X>
44 constexpr auto operator()(F&& f, X&& x) const {
45 (void)static_cast<F&&>(f)(x);
46 return hana::lift<M>(static_cast<X&&>(x));
51 template <typename M, bool condition>
52 struct tap_impl<M, when<condition>> : default_ {
54 static constexpr auto apply(F&& f)
55 { return hana::partial(detail::tap_helper<M>{}, static_cast<F&&>(f)); }
57 BOOST_HANA_NAMESPACE_END
59 #endif // !BOOST_HANA_TAP_HPP