]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Forward declares `boost::hana::duplicate`. | |
4 | ||
b32b8144 | 5 | @copyright Louis Dionne 2013-2017 |
7c673cae FG |
6 | Distributed under the Boost Software License, Version 1.0. |
7 | (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |
8 | */ | |
9 | ||
10 | #ifndef BOOST_HANA_FWD_DUPLICATE_HPP | |
11 | #define BOOST_HANA_FWD_DUPLICATE_HPP | |
12 | ||
13 | #include <boost/hana/config.hpp> | |
14 | #include <boost/hana/core/when.hpp> | |
15 | ||
16 | ||
1e59de90 | 17 | namespace boost { namespace hana { |
7c673cae FG |
18 | //! Add an extra layer of comonadic context to a comonadic value. |
19 | //! @ingroup group-Comonad | |
20 | //! | |
21 | //! Given a value already in a comonadic context, `duplicate` wraps this | |
22 | //! value with an additional layer of comonadic context. This can be seen | |
23 | //! as the dual operation to `flatten` from the Monad concept. | |
24 | //! | |
25 | //! | |
26 | //! Signature | |
27 | //! --------- | |
28 | //! Given a Comonad `W`, the signature is | |
29 | //! \f$ | |
30 | //! \mathtt{duplicate} : W(T) \to W(W(T)) | |
31 | //! \f$ | |
32 | //! | |
33 | //! @param w | |
34 | //! The value to wrap in an additional level of comonadic context. | |
35 | //! | |
36 | //! | |
37 | //! Example | |
38 | //! ------- | |
39 | //! @include example/duplicate.cpp | |
40 | #ifdef BOOST_HANA_DOXYGEN_INVOKED | |
41 | constexpr auto duplicate = [](auto&& w) -> decltype(auto) { | |
42 | return tag-dispatched; | |
43 | }; | |
44 | #else | |
45 | template <typename W, typename = void> | |
46 | struct duplicate_impl : duplicate_impl<W, when<true>> { }; | |
47 | ||
48 | struct duplicate_t { | |
49 | template <typename W_> | |
50 | constexpr decltype(auto) operator()(W_&& w) const; | |
51 | }; | |
52 | ||
1e59de90 | 53 | BOOST_HANA_INLINE_VARIABLE constexpr duplicate_t duplicate{}; |
7c673cae | 54 | #endif |
1e59de90 | 55 | }} // end namespace boost::hana |
7c673cae FG |
56 | |
57 | #endif // !BOOST_HANA_FWD_DUPLICATE_HPP |