| 1 | /*! |
| 2 | @file |
| 3 | Defines `boost::hana::fuse`. |
| 4 | |
| 5 | Copyright Louis Dionne 2013-2022 |
| 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) |
| 8 | */ |
| 9 | |
| 10 | #ifndef BOOST_HANA_FUSE_HPP |
| 11 | #define BOOST_HANA_FUSE_HPP |
| 12 | |
| 13 | #include <boost/hana/fwd/fuse.hpp> |
| 14 | |
| 15 | #include <boost/hana/config.hpp> |
| 16 | #include <boost/hana/detail/decay.hpp> |
| 17 | #include <boost/hana/unpack.hpp> |
| 18 | |
| 19 | |
| 20 | namespace boost { namespace hana { |
| 21 | namespace detail { |
| 22 | template <typename F> |
| 23 | struct fused { |
| 24 | F f; |
| 25 | template <typename Xs> |
| 26 | constexpr decltype(auto) operator()(Xs&& xs) const& |
| 27 | { return hana::unpack(static_cast<Xs&&>(xs), f); } |
| 28 | |
| 29 | template <typename Xs> |
| 30 | constexpr decltype(auto) operator()(Xs&& xs) & |
| 31 | { return hana::unpack(static_cast<Xs&&>(xs), f); } |
| 32 | |
| 33 | template <typename Xs> |
| 34 | constexpr decltype(auto) operator()(Xs&& xs) && |
| 35 | { return hana::unpack(static_cast<Xs&&>(xs), static_cast<F&&>(f)); } |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | //! @cond |
| 40 | template <typename F> |
| 41 | constexpr auto fuse_t::operator()(F&& f) const { |
| 42 | return detail::fused<typename detail::decay<F>::type>{static_cast<F&&>(f)}; |
| 43 | } |
| 44 | //! @endcond |
| 45 | }} // end namespace boost::hana |
| 46 | |
| 47 | #endif // !BOOST_HANA_FUSE_HPP |
| 48 | |