File indexing completed on 2025-01-18 09:38:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_EXTEND_HPP
0011 #define BOOST_HANA_EXTEND_HPP
0012
0013 #include <boost/hana/fwd/extend.hpp>
0014
0015 #include <boost/hana/concept/comonad.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/duplicate.hpp>
0019 #include <boost/hana/transform.hpp>
0020
0021
0022 namespace boost { namespace hana {
0023
0024 template <typename W_, typename F>
0025 constexpr decltype(auto) extend_t::operator()(W_&& w, F&& f) const {
0026 using W = typename hana::tag_of<W_>::type;
0027 using Extend = BOOST_HANA_DISPATCH_IF(extend_impl<W>,
0028 hana::Comonad<W>::value
0029 );
0030
0031 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0032 static_assert(hana::Comonad<W>::value,
0033 "hana::extend(w, f) requires 'w' to be a Comonad");
0034 #endif
0035
0036 return Extend::apply(static_cast<W_&&>(w), static_cast<F&&>(f));
0037 }
0038
0039
0040 template <typename W, bool condition>
0041 struct extend_impl<W, when<condition>> : default_ {
0042 template <typename X, typename F>
0043 static constexpr decltype(auto) apply(X&& x, F&& f) {
0044 return hana::transform(hana::duplicate(static_cast<X&&>(x)),
0045 static_cast<F&&>(f));
0046 }
0047 };
0048 }}
0049
0050 #endif