Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*!
0002 @file
0003 Defines `boost::hana::then`.
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_THEN_HPP
0011 #define BOOST_HANA_THEN_HPP
0012 
0013 #include <boost/hana/fwd/then.hpp>
0014 
0015 #include <boost/hana/chain.hpp>
0016 #include <boost/hana/concept/monad.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/functional/always.hpp>
0020 
0021 
0022 namespace boost { namespace hana {
0023     //! @cond
0024     template <typename Before, typename Xs>
0025     constexpr decltype(auto) then_t::operator()(Before&& before, Xs&& xs) const {
0026         using M = typename hana::tag_of<Before>::type;
0027         using Then = BOOST_HANA_DISPATCH_IF(then_impl<M>,
0028             hana::Monad<M>::value &&
0029             hana::Monad<Xs>::value
0030         );
0031 
0032     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0033         static_assert(hana::Monad<M>::value,
0034         "hana::then(before, xs) requires 'before' to be a Monad");
0035 
0036         static_assert(hana::Monad<Xs>::value,
0037         "hana::then(before, xs) requires 'xs' to be a Monad");
0038     #endif
0039 
0040         return Then::apply(static_cast<Before&&>(before),
0041                            static_cast<Xs&&>(xs));
0042     }
0043     //! @endcond
0044 
0045     template <typename M, bool condition>
0046     struct then_impl<M, when<condition>> : default_ {
0047         template <typename Xs, typename Ys>
0048         static constexpr decltype(auto) apply(Xs&& xs, Ys&& ys) {
0049             return hana::chain(static_cast<Xs&&>(xs),
0050                                hana::always(static_cast<Ys&&>(ys)));
0051         }
0052     };
0053 }} // end namespace boost::hana
0054 
0055 #endif // !BOOST_HANA_THEN_HPP