3 Defines `boost::hana::extend`.
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_EXTEND_HPP
11 #define BOOST_HANA_EXTEND_HPP
13 #include <boost/hana/fwd/extend.hpp>
15 #include <boost/hana/concept/comonad.hpp>
16 #include <boost/hana/config.hpp>
17 #include <boost/hana/core/dispatch.hpp>
18 #include <boost/hana/duplicate.hpp>
19 #include <boost/hana/transform.hpp>
22 BOOST_HANA_NAMESPACE_BEGIN
24 template <typename W_, typename F>
25 constexpr decltype(auto) extend_t::operator()(W_&& w, F&& f) const {
26 using W = typename hana::tag_of<W_>::type;
27 using Extend = BOOST_HANA_DISPATCH_IF(extend_impl<W>,
28 hana::Comonad<W>::value
31 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
32 static_assert(hana::Comonad<W>::value,
33 "hana::extend(w, f) requires 'w' to be a Comonad");
36 return Extend::apply(static_cast<W_&&>(w), static_cast<F&&>(f));
40 template <typename W, bool condition>
41 struct extend_impl<W, when<condition>> : default_ {
42 template <typename X, typename F>
43 static constexpr decltype(auto) apply(X&& x, F&& f) {
44 return hana::transform(hana::duplicate(static_cast<X&&>(x)),
48 BOOST_HANA_NAMESPACE_END
50 #endif // !BOOST_HANA_EXTEND_HPP