]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `boost::hana::suffix`. | |
4 | ||
5 | @copyright Louis Dionne 2013-2016 | |
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_SUFFIX_HPP | |
11 | #define BOOST_HANA_SUFFIX_HPP | |
12 | ||
13 | #include <boost/hana/fwd/suffix.hpp> | |
14 | ||
15 | #include <boost/hana/chain.hpp> | |
16 | #include <boost/hana/concept/monad_plus.hpp> | |
17 | #include <boost/hana/config.hpp> | |
18 | #include <boost/hana/core/dispatch.hpp> | |
19 | #include <boost/hana/functional/partial.hpp> | |
20 | #include <boost/hana/lift.hpp> | |
21 | #include <boost/hana/prepend.hpp> | |
22 | ||
23 | ||
24 | BOOST_HANA_NAMESPACE_BEGIN | |
25 | //! @cond | |
26 | template <typename Xs, typename Sfx> | |
27 | constexpr auto suffix_t::operator()(Xs&& xs, Sfx&& sfx) const { | |
28 | using M = typename hana::tag_of<Xs>::type; | |
29 | using Suffix = BOOST_HANA_DISPATCH_IF(suffix_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::suffix(xs, sfx) requires 'xs' to be a MonadPlus"); | |
36 | #endif | |
37 | ||
38 | return Suffix::apply(static_cast<Xs&&>(xs), static_cast<Sfx&&>(sfx)); | |
39 | } | |
40 | //! @endcond | |
41 | ||
42 | template <typename M, bool condition> | |
43 | struct suffix_impl<M, when<condition>> : default_ { | |
44 | template <typename Xs, typename Z> | |
45 | static constexpr auto apply(Xs&& xs, Z&& z) { | |
46 | return hana::chain(static_cast<Xs&&>(xs), | |
47 | hana::partial(hana::prepend, hana::lift<M>(static_cast<Z&&>(z)))); | |
48 | } | |
49 | }; | |
50 | BOOST_HANA_NAMESPACE_END | |
51 | ||
52 | #endif // !BOOST_HANA_SUFFIX_HPP |