1 /*=============================================================================
2 Copyright (c) 2014 Paul Fultz II
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
8 #ifndef BOOST_HOF_GUARD_FUNCTION_TAP_H
9 #define BOOST_HOF_GUARD_FUNCTION_TAP_H
17 /// The `tap` function invokes a function on the first argument passed in and
18 /// then returns the first argument. This is useful in a chain of pipable
19 /// function to perform operations on intermediate results. As a result, this
20 /// function is [`pipable`](/include/boost/hof/pipable).
25 /// template<class T, class F>
26 /// pipable constexpr T tap(T&& x, const F& f);
33 /// * [UnaryInvocable](UnaryInvocable)
38 /// #include <boost/hof.hpp>
39 /// #include <cassert>
40 /// #include <iostream>
41 /// using namespace boost::hof;
45 /// template<class T, class U>
46 /// T operator()(T x, U y) const
52 /// const pipable_adaptor<sum_f> sum = {};
55 /// int r = 1 | sum(2) | tap([](int i) { std::cout << i; }) | sum(2);
60 #include <boost/hof/pipable.hpp>
61 #include <boost/hof/apply.hpp>
62 #include <boost/hof/detail/static_const_var.hpp>
64 namespace boost { namespace hof { namespace detail {
68 template<class T, class F>
69 constexpr T operator()(T&& x, const F& f) const
70 BOOST_HOF_RETURNS_DEDUCE_NOEXCEPT((boost::hof::apply(f, x), BOOST_HOF_FORWARD(T)(x)))
72 return boost::hof::apply(f, x), BOOST_HOF_FORWARD(T)(x);
78 BOOST_HOF_DECLARE_STATIC_VAR(tap, pipable_adaptor<detail::tap_f>);
81 }} // namespace boost::hof