Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:05

0001 /*!
0002 @file
0003 Defines `boost::hana::replace`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_REPLACE_HPP
0011 #define BOOST_HANA_REPLACE_HPP
0012 
0013 #include <boost/hana/fwd/replace.hpp>
0014 
0015 #include <boost/hana/concept/functor.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/equal.hpp>
0019 #include <boost/hana/replace_if.hpp>
0020 
0021 
0022 namespace boost { namespace hana {
0023     //! @cond
0024     template <typename Xs, typename OldVal, typename NewVal>
0025     constexpr auto replace_t::operator()(Xs&& xs, OldVal&& oldval, NewVal&& newval) const {
0026         using S = typename hana::tag_of<Xs>::type;
0027         using Replace = BOOST_HANA_DISPATCH_IF(replace_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(xs, oldval, newval) requires 'xs' to be a Functor");
0034     #endif
0035 
0036         return Replace::apply(static_cast<Xs&&>(xs),
0037                               static_cast<OldVal&&>(oldval),
0038                               static_cast<NewVal&&>(newval));
0039     }
0040     //! @endcond
0041 
0042     template <typename Fun, bool condition>
0043     struct replace_impl<Fun, when<condition>> : default_ {
0044         template <typename Xs, typename OldVal, typename NewVal>
0045         static constexpr decltype(auto)
0046         apply(Xs&& xs, OldVal&& oldval, NewVal&& newval) {
0047             return hana::replace_if(
0048                 static_cast<Xs&&>(xs),
0049                 hana::equal.to(static_cast<OldVal&&>(oldval)),
0050                 static_cast<NewVal&&>(newval)
0051             );
0052         }
0053     };
0054 }} // end namespace boost::hana
0055 
0056 #endif // !BOOST_HANA_REPLACE_HPP