3 Defines `boost::hana::replace_if`.
5 @copyright Louis Dionne 2013-2017
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)
10 #ifndef BOOST_HANA_REPLACE_IF_HPP
11 #define BOOST_HANA_REPLACE_IF_HPP
13 #include <boost/hana/fwd/replace_if.hpp>
15 #include <boost/hana/adjust_if.hpp>
16 #include <boost/hana/concept/functor.hpp>
17 #include <boost/hana/config.hpp>
18 #include <boost/hana/core/dispatch.hpp>
19 #include <boost/hana/functional/always.hpp>
22 BOOST_HANA_NAMESPACE_BEGIN
24 template <typename Xs, typename Pred, typename Value>
25 constexpr auto replace_if_t::operator()(Xs&& xs, Pred&& pred, Value&& value) const {
26 using S = typename hana::tag_of<Xs>::type;
27 using ReplaceIf = BOOST_HANA_DISPATCH_IF(replace_if_impl<S>,
28 hana::Functor<S>::value
31 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
32 static_assert(hana::Functor<S>::value,
33 "hana::replace_if(xs, pred, value) requires 'xs' to be a Functor");
36 return ReplaceIf::apply(static_cast<Xs&&>(xs),
37 static_cast<Pred&&>(pred),
38 static_cast<Value&&>(value));
42 template <typename Fun, bool condition>
43 struct replace_if_impl<Fun, when<condition>> : default_ {
44 template <typename Xs, typename Pred, typename Value>
45 static constexpr auto apply(Xs&& xs, Pred&& pred, Value&& v) {
46 return hana::adjust_if(static_cast<Xs&&>(xs),
47 static_cast<Pred&&>(pred),
48 hana::always(static_cast<Value&&>(v))
52 BOOST_HANA_NAMESPACE_END
54 #endif // !BOOST_HANA_REPLACE_IF_HPP