Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:43:35

0001 /*!
0002 @file
0003 Defines `boost::hana::append`.
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_APPEND_HPP
0011 #define BOOST_HANA_APPEND_HPP
0012 
0013 #include <boost/hana/fwd/append.hpp>
0014 
0015 #include <boost/hana/at.hpp>
0016 #include <boost/hana/concat.hpp>
0017 #include <boost/hana/concept/monad_plus.hpp>
0018 #include <boost/hana/concept/sequence.hpp>
0019 #include <boost/hana/config.hpp>
0020 #include <boost/hana/core/dispatch.hpp>
0021 #include <boost/hana/core/make.hpp>
0022 #include <boost/hana/length.hpp>
0023 #include <boost/hana/lift.hpp>
0024 
0025 #include <cstddef>
0026 #include <utility>
0027 
0028 
0029 namespace boost { namespace hana {
0030     //! @cond
0031     template <typename Xs, typename X>
0032     constexpr auto append_t::operator()(Xs&& xs, X&& x) const {
0033         using M = typename hana::tag_of<Xs>::type;
0034         using Append = BOOST_HANA_DISPATCH_IF(append_impl<M>,
0035             hana::MonadPlus<M>::value
0036         );
0037 
0038     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0039         static_assert(hana::MonadPlus<M>::value,
0040         "hana::append(xs, x) requires 'xs' to be a MonadPlus");
0041     #endif
0042 
0043         return Append::apply(static_cast<Xs&&>(xs), static_cast<X&&>(x));
0044     }
0045     //! @endcond
0046 
0047     template <typename M, bool condition>
0048     struct append_impl<M, when<condition>> : default_ {
0049         template <typename Xs, typename X>
0050         static constexpr auto apply(Xs&& xs, X&& x) {
0051             return hana::concat(static_cast<Xs&&>(xs),
0052                                 hana::lift<M>(static_cast<X&&>(x)));
0053         }
0054     };
0055 
0056     template <typename S>
0057     struct append_impl<S, when<Sequence<S>::value>> {
0058         template <typename Xs, typename X, std::size_t ...i>
0059         static constexpr auto append_helper(Xs&& xs, X&& x, std::index_sequence<i...>) {
0060             return hana::make<S>(
0061                 hana::at_c<i>(static_cast<Xs&&>(xs))..., static_cast<X&&>(x)
0062             );
0063         }
0064 
0065         template <typename Xs, typename X>
0066         static constexpr auto apply(Xs&& xs, X&& x) {
0067             constexpr std::size_t N = decltype(hana::length(xs))::value;
0068             return append_helper(static_cast<Xs&&>(xs), static_cast<X&&>(x),
0069                                  std::make_index_sequence<N>{});
0070         }
0071     };
0072 }} // end namespace boost::hana
0073 
0074 #endif // !BOOST_HANA_APPEND_HPP