extract.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*!
  2. @file
  3. Forward declares `boost::hana::extract`.
  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_EXTRACT_HPP
  9. #define BOOST_HANA_FWD_EXTRACT_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Extract a value in a given comonadic context.
  14. //! @ingroup group-Comonad
  15. //!
  16. //! Given a value inside a comonadic context, extract it from that
  17. //! context, performing whatever effects are mandated by that context.
  18. //! This can be seen as the dual operation to the `lift` method of the
  19. //! Applicative concept.
  20. //!
  21. //!
  22. //! Signature
  23. //! ---------
  24. //! Given a Comonad `W`, the signature is
  25. //! \f$
  26. //! \mathtt{extract} : W(T) \to T
  27. //! \f$
  28. //!
  29. //! @param w
  30. //! The value to be extracted inside a comonadic context.
  31. //!
  32. //!
  33. //! Example
  34. //! -------
  35. //! @include example/extract.cpp
  36. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  37. constexpr auto extract = [](auto&& w) -> decltype(auto) {
  38. return tag-dispatched;
  39. };
  40. #else
  41. template <typename W, typename = void>
  42. struct extract_impl : extract_impl<W, when<true>> { };
  43. struct extract_t {
  44. template <typename W_>
  45. constexpr decltype(auto) operator()(W_&& w) const;
  46. };
  47. constexpr extract_t extract{};
  48. #endif
  49. BOOST_HANA_NAMESPACE_END
  50. #endif // !BOOST_HANA_FWD_EXTRACT_HPP