fuse.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*!
  2. @file
  3. Defines `boost::hana::fuse`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_FUSE_HPP
  9. #define BOOST_HANA_FUSE_HPP
  10. #include <boost/hana/fwd/fuse.hpp>
  11. #include <boost/hana/config.hpp>
  12. #include <boost/hana/detail/decay.hpp>
  13. #include <boost/hana/unpack.hpp>
  14. BOOST_HANA_NAMESPACE_BEGIN
  15. namespace detail {
  16. template <typename F>
  17. struct fused {
  18. F f;
  19. template <typename Xs>
  20. constexpr decltype(auto) operator()(Xs&& xs) const&
  21. { return hana::unpack(static_cast<Xs&&>(xs), f); }
  22. template <typename Xs>
  23. constexpr decltype(auto) operator()(Xs&& xs) &
  24. { return hana::unpack(static_cast<Xs&&>(xs), f); }
  25. template <typename Xs>
  26. constexpr decltype(auto) operator()(Xs&& xs) &&
  27. { return hana::unpack(static_cast<Xs&&>(xs), static_cast<F&&>(f)); }
  28. };
  29. }
  30. //! @cond
  31. template <typename F>
  32. constexpr auto fuse_t::operator()(F&& f) const {
  33. return detail::fused<typename detail::decay<F>::type>{static_cast<F&&>(f)};
  34. }
  35. //! @endcond
  36. BOOST_HANA_NAMESPACE_END
  37. #endif // !BOOST_HANA_FUSE_HPP