]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `boost::hana::remove`. | |
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_REMOVE_HPP | |
11 | #define BOOST_HANA_REMOVE_HPP | |
12 | ||
13 | #include <boost/hana/fwd/remove.hpp> | |
14 | ||
15 | #include <boost/hana/concept/monad_plus.hpp> | |
16 | #include <boost/hana/config.hpp> | |
17 | #include <boost/hana/core/dispatch.hpp> | |
18 | #include <boost/hana/equal.hpp> | |
19 | #include <boost/hana/filter.hpp> | |
20 | #include <boost/hana/functional/compose.hpp> | |
21 | #include <boost/hana/not.hpp> | |
22 | ||
23 | ||
24 | BOOST_HANA_NAMESPACE_BEGIN | |
25 | //! @cond | |
26 | template <typename Xs, typename Value> | |
27 | constexpr auto remove_t::operator()(Xs&& xs, Value&& value) const { | |
28 | using M = typename hana::tag_of<Xs>::type; | |
29 | using Remove = BOOST_HANA_DISPATCH_IF(remove_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::remove(xs, value) requires 'xs' to be a MonadPlus"); | |
36 | #endif | |
37 | ||
38 | return Remove::apply(static_cast<Xs&&>(xs), | |
39 | static_cast<Value&&>(value)); | |
40 | } | |
41 | //! @endcond | |
42 | ||
43 | template <typename M, bool condition> | |
44 | struct remove_impl<M, when<condition>> : default_ { | |
45 | template <typename Xs, typename Value> | |
46 | static constexpr auto apply(Xs&& xs, Value&& value) { | |
47 | return hana::filter(static_cast<Xs&&>(xs), | |
48 | hana::compose(hana::not_, | |
49 | hana::equal.to(static_cast<Value&&>(value)))); | |
50 | } | |
51 | }; | |
52 | BOOST_HANA_NAMESPACE_END | |
53 | ||
54 | #endif // !BOOST_HANA_REMOVE_HPP |