extend.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*!
  2. @file
  3. Forward declares `boost::hana::extend`.
  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_EXTEND_HPP
  9. #define BOOST_HANA_FWD_EXTEND_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Comonadic application of a function to a comonadic value.
  14. //! @ingroup group-Comonad
  15. //!
  16. //! Given a comonadic value and a function accepting a comonadic input,
  17. //! `extend` returns the result of applying the function to that input
  18. //! inside the comonadic context.
  19. //!
  20. //!
  21. //! Signature
  22. //! ---------
  23. //! Given a Comonad `W` and a function of type \f$ W(T) \to U \f$, the
  24. //! signature is
  25. //! \f$
  26. //! \mathtt{extend} : W(T) \times (W(T) \to U) \to W(U)
  27. //! \f$
  28. //!
  29. //! @param w
  30. //! A comonadic value to call the function with.
  31. //!
  32. //! @param f
  33. //! A function of signature \f$ W(T) \to U \f$ to be applied to its
  34. //! comonadic argument inside the comonadic context.
  35. //!
  36. //!
  37. //! Example
  38. //! -------
  39. //! @include example/extend.cpp
  40. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  41. constexpr auto extend = [](auto&& w, auto&& f) -> decltype(auto) {
  42. return tag-dispatched;
  43. };
  44. #else
  45. template <typename W, typename = void>
  46. struct extend_impl : extend_impl<W, when<true>> { };
  47. struct extend_t {
  48. template <typename W_, typename F>
  49. constexpr decltype(auto) operator()(W_&& w, F&& f) const;
  50. };
  51. constexpr extend_t extend{};
  52. #endif
  53. BOOST_HANA_NAMESPACE_END
  54. #endif // !BOOST_HANA_FWD_EXTEND_HPP