chain.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*!
  2. @file
  3. Forward declares `boost::hana::chain`.
  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_CHAIN_HPP
  9. #define BOOST_HANA_FWD_CHAIN_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Feed a monadic value into a monadic computation.
  14. //! @ingroup group-Monad
  15. //!
  16. //! Given a monadic value and a monadic function, `chain` feeds the
  17. //! monadic value into the function, thus performing some Monad-specific
  18. //! effects, and returns the result. An implementation of `chain` must
  19. //! satisfy
  20. //! @code
  21. //! chain(xs, f) == flatten(transform(xs, f))
  22. //! @endcode
  23. //!
  24. //!
  25. //! Signature
  26. //! ---------
  27. //! For a monad `M`, given a monadic value of type `M(A)` and a monadic
  28. //! function @f$ f : A \to M(B) @f$, `chain` has the signature
  29. //! @f$
  30. //! \mathtt{chain} : M(A) \times (A \to M(B)) \to M(B)
  31. //! @f$.
  32. //!
  33. //! @param xs
  34. //! A monadic value to be fed to the function `f`.
  35. //!
  36. //! @param f
  37. //! A function taking a normal value in the `xs` structure, and returning
  38. //! a monadic value. This function is called as `f(x)`, where `x` is an
  39. //! element of the structure `xs`.
  40. //!
  41. //!
  42. //! Example
  43. //! -------
  44. //! @include example/chain.cpp
  45. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  46. constexpr auto chain = [](auto&& xs, auto&& f) -> decltype(auto) {
  47. return tag-dispatched;
  48. };
  49. #else
  50. template <typename M, typename = void>
  51. struct chain_impl : chain_impl<M, when<true>> { };
  52. struct chain_t {
  53. template <typename Xs, typename F>
  54. constexpr decltype(auto) operator()(Xs&& xs, F&& f) const;
  55. };
  56. constexpr chain_t chain{};
  57. #endif
  58. BOOST_HANA_NAMESPACE_END
  59. #endif // !BOOST_HANA_FWD_CHAIN_HPP