1/*!
2@file
3Defines `boost::hana::replace_if`.
4
5Copyright Louis Dionne 2013-2022
6Distributed 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_REPLACE_IF_HPP
11#define BOOST_HANA_REPLACE_IF_HPP
12
13#include <boost/hana/fwd/replace_if.hpp>
14
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>
20
21
22namespace boost { namespace hana {
23 //! @cond
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
29 );
30
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");
34 #endif
35
36 return ReplaceIf::apply(static_cast<Xs&&>(xs),
37 static_cast<Pred&&>(pred),
38 static_cast<Value&&>(value));
39 }
40 //! @endcond
41
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))
49 );
50 }
51 };
52}} // end namespace boost::hana
53
54#endif // !BOOST_HANA_REPLACE_IF_HPP
55

source code of boost/libs/hana/include/boost/hana/replace_if.hpp