]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `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_DUPLICATE_HPP | |
11 | #define BOOST_HANA_DUPLICATE_HPP | |
12 | ||
13 | #include <boost/hana/fwd/duplicate.hpp> | |
14 | ||
15 | #include <boost/hana/concept/comonad.hpp> | |
16 | #include <boost/hana/config.hpp> | |
17 | #include <boost/hana/core/dispatch.hpp> | |
18 | #include <boost/hana/extend.hpp> | |
19 | #include <boost/hana/functional/id.hpp> | |
20 | ||
21 | ||
22 | BOOST_HANA_NAMESPACE_BEGIN | |
23 | //! @cond | |
24 | template <typename W_> | |
25 | constexpr decltype(auto) duplicate_t::operator()(W_&& w) const { | |
26 | using W = typename hana::tag_of<W_>::type; | |
27 | using Duplicate = BOOST_HANA_DISPATCH_IF(duplicate_impl<W>, | |
28 | hana::Comonad<W>::value | |
29 | ); | |
30 | ||
31 | #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS | |
32 | static_assert(hana::Comonad<W>::value, | |
33 | "hana::duplicate(w) requires 'w' to be a Comonad"); | |
34 | #endif | |
35 | ||
36 | return Duplicate::apply(static_cast<W_&&>(w)); | |
37 | } | |
38 | //! @endcond | |
39 | ||
40 | template <typename W, bool condition> | |
41 | struct duplicate_impl<W, when<condition>> : default_ { | |
42 | template <typename X> | |
43 | static constexpr decltype(auto) apply(X&& x) | |
44 | { return hana::extend(static_cast<X&&>(x), hana::id); } | |
45 | }; | |
46 | BOOST_HANA_NAMESPACE_END | |
47 | ||
48 | #endif // !BOOST_HANA_DUPLICATE_HPP |