]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `boost::hana::prefix`. | |
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_PREFIX_HPP | |
11 | #define BOOST_HANA_PREFIX_HPP | |
12 | ||
13 | #include <boost/hana/fwd/prefix.hpp> | |
14 | ||
15 | #include <boost/hana/append.hpp> | |
16 | #include <boost/hana/chain.hpp> | |
17 | #include <boost/hana/concept/monad_plus.hpp> | |
18 | #include <boost/hana/config.hpp> | |
19 | #include <boost/hana/core/dispatch.hpp> | |
20 | #include <boost/hana/functional/partial.hpp> | |
21 | #include <boost/hana/lift.hpp> | |
22 | ||
23 | ||
24 | BOOST_HANA_NAMESPACE_BEGIN | |
25 | //! @cond | |
26 | template <typename Xs, typename Pref> | |
27 | constexpr auto prefix_t::operator()(Xs&& xs, Pref&& pref) const { | |
28 | using M = typename hana::tag_of<Xs>::type; | |
29 | using Prefix = BOOST_HANA_DISPATCH_IF(prefix_impl<M>, | |
30 | hana::MonadPlus<M>::value | |
31 | ); | |
32 | ||
33 | #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS | |
34 | static_assert(hana::MonadPlus<M>::value, | |
35 | "hana::prefix(xs, pref) requires 'xs' to be a MonadPlus"); | |
36 | #endif | |
37 | ||
38 | return Prefix::apply(static_cast<Xs&&>(xs), static_cast<Pref&&>(pref)); | |
39 | } | |
40 | //! @endcond | |
41 | ||
42 | template <typename M, bool condition> | |
43 | struct prefix_impl<M, when<condition>> : default_ { | |
44 | template <typename Xs, typename Z> | |
45 | static constexpr decltype(auto) apply(Xs&& xs, Z&& z) { | |
46 | return hana::chain(static_cast<Xs&&>(xs), | |
47 | hana::partial(hana::append, hana::lift<M>(static_cast<Z&&>(z)))); | |
48 | } | |
49 | }; | |
50 | BOOST_HANA_NAMESPACE_END | |
51 | ||
52 | #endif // !BOOST_HANA_PREFIX_HPP |