fuse.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*!
  2. @file
  3. Forward declares `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_FWD_FUSE_HPP
  9. #define BOOST_HANA_FWD_FUSE_HPP
  10. #include <boost/hana/config.hpp>
  11. BOOST_HANA_NAMESPACE_BEGIN
  12. //! Transform a function taking multiple arguments into a function that
  13. //! can be called with a compile-time `Foldable`.
  14. //! @ingroup group-Foldable
  15. //!
  16. //!
  17. //! This function is provided for convenience as a different way of
  18. //! calling `unpack`. Specifically, `fuse(f)` is a function such that
  19. //! @code
  20. //! fuse(f)(foldable) == unpack(foldable, f)
  21. //! == f(x...)
  22. //! @endcode
  23. //! where `x...` are the elements in the foldable. This function is
  24. //! useful when one wants to create a function that accepts a foldable
  25. //! which is not known yet.
  26. //!
  27. //! @note
  28. //! This function is not tag-dispatched; customize `unpack` instead.
  29. //!
  30. //!
  31. //! Example
  32. //! -------
  33. //! @include example/fuse.cpp
  34. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  35. constexpr auto fuse = [](auto&& f) {
  36. return [perfect-capture](auto&& xs) -> decltype(auto) {
  37. return unpack(forwarded(xs), forwarded(f));
  38. };
  39. };
  40. #else
  41. struct fuse_t {
  42. template <typename F>
  43. constexpr auto operator()(F&& f) const;
  44. };
  45. constexpr fuse_t fuse{};
  46. #endif
  47. BOOST_HANA_NAMESPACE_END
  48. #endif // !BOOST_HANA_FWD_FUSE_HPP