1 /*! 2 @file 3 Defines `boost::hana::chain`. 4 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) 8 */ 9 10 #ifndef BOOST_HANA_CHAIN_HPP 11 #define BOOST_HANA_CHAIN_HPP 12 13 #include <boost/hana/fwd/chain.hpp> 14 15 #include <boost/hana/concept/monad.hpp> 16 #include <boost/hana/config.hpp> 17 #include <boost/hana/core/dispatch.hpp> 18 #include <boost/hana/flatten.hpp> 19 #include <boost/hana/transform.hpp> 20 21 22 BOOST_HANA_NAMESPACE_BEGIN 23 //! @cond 24 template <typename Xs, typename F> operator ()(Xs && xs,F && f) const25 constexpr decltype(auto) chain_t::operator()(Xs&& xs, F&& f) const { 26 using M = typename hana::tag_of<Xs>::type; 27 using Chain = BOOST_HANA_DISPATCH_IF(chain_impl<M>, 28 hana::Monad<M>::value 29 ); 30 31 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS 32 static_assert(hana::Monad<M>::value, 33 "hana::chain(xs, f) requires 'xs' to be a Monad"); 34 #endif 35 36 return Chain::apply(static_cast<Xs&&>(xs), static_cast<F&&>(f)); 37 } 38 //! @endcond 39 40 template <typename M, bool condition> 41 struct chain_impl<M, when<condition>> : default_ { 42 template <typename Xs, typename F> applychain_impl43 static constexpr auto apply(Xs&& xs, F&& f) { 44 return hana::flatten(hana::transform(static_cast<Xs&&>(xs), 45 static_cast<F&&>(f))); 46 } 47 }; 48 BOOST_HANA_NAMESPACE_END 49 50 #endif // !BOOST_HANA_CHAIN_HPP 51