duplicate.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. @file
  3. Forward declares `boost::hana::duplicate`.
  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_DUPLICATE_HPP
  9. #define BOOST_HANA_FWD_DUPLICATE_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Add an extra layer of comonadic context to a comonadic value.
  14. //! @ingroup group-Comonad
  15. //!
  16. //! Given a value already in a comonadic context, `duplicate` wraps this
  17. //! value with an additional layer of comonadic context. This can be seen
  18. //! as the dual operation to `flatten` from the Monad concept.
  19. //!
  20. //!
  21. //! Signature
  22. //! ---------
  23. //! Given a Comonad `W`, the signature is
  24. //! \f$
  25. //! \mathtt{duplicate} : W(T) \to W(W(T))
  26. //! \f$
  27. //!
  28. //! @param w
  29. //! The value to wrap in an additional level of comonadic context.
  30. //!
  31. //!
  32. //! Example
  33. //! -------
  34. //! @include example/duplicate.cpp
  35. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  36. constexpr auto duplicate = [](auto&& w) -> decltype(auto) {
  37. return tag-dispatched;
  38. };
  39. #else
  40. template <typename W, typename = void>
  41. struct duplicate_impl : duplicate_impl<W, when<true>> { };
  42. struct duplicate_t {
  43. template <typename W_>
  44. constexpr decltype(auto) operator()(W_&& w) const;
  45. };
  46. constexpr duplicate_t duplicate{};
  47. #endif
  48. BOOST_HANA_NAMESPACE_END
  49. #endif // !BOOST_HANA_FWD_DUPLICATE_HPP