File indexing completed on 2025-01-18 09:38:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_REPLACE_IF_HPP
0011 #define BOOST_HANA_REPLACE_IF_HPP
0012
0013 #include <boost/hana/fwd/replace_if.hpp>
0014
0015 #include <boost/hana/adjust_if.hpp>
0016 #include <boost/hana/concept/functor.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/functional/always.hpp>
0020
0021
0022 namespace boost { namespace hana {
0023
0024 template <typename Xs, typename Pred, typename Value>
0025 constexpr auto replace_if_t::operator()(Xs&& xs, Pred&& pred, Value&& value) const {
0026 using S = typename hana::tag_of<Xs>::type;
0027 using ReplaceIf = BOOST_HANA_DISPATCH_IF(replace_if_impl<S>,
0028 hana::Functor<S>::value
0029 );
0030
0031 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0032 static_assert(hana::Functor<S>::value,
0033 "hana::replace_if(xs, pred, value) requires 'xs' to be a Functor");
0034 #endif
0035
0036 return ReplaceIf::apply(static_cast<Xs&&>(xs),
0037 static_cast<Pred&&>(pred),
0038 static_cast<Value&&>(value));
0039 }
0040
0041
0042 template <typename Fun, bool condition>
0043 struct replace_if_impl<Fun, when<condition>> : default_ {
0044 template <typename Xs, typename Pred, typename Value>
0045 static constexpr auto apply(Xs&& xs, Pred&& pred, Value&& v) {
0046 return hana::adjust_if(static_cast<Xs&&>(xs),
0047 static_cast<Pred&&>(pred),
0048 hana::always(static_cast<Value&&>(v))
0049 );
0050 }
0051 };
0052 }}
0053
0054 #endif