File indexing completed on 2025-01-18 09:38:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_CONCAT_HPP
0011 #define BOOST_HANA_CONCAT_HPP
0012
0013 #include <boost/hana/fwd/concat.hpp>
0014
0015 #include <boost/hana/at.hpp>
0016 #include <boost/hana/concept/monad_plus.hpp>
0017 #include <boost/hana/concept/sequence.hpp>
0018 #include <boost/hana/config.hpp>
0019 #include <boost/hana/core/dispatch.hpp>
0020 #include <boost/hana/core/make.hpp>
0021 #include <boost/hana/length.hpp>
0022
0023 #include <cstddef>
0024 #include <type_traits>
0025 #include <utility>
0026
0027
0028 namespace boost { namespace hana {
0029
0030 template <typename Xs, typename Ys>
0031 constexpr auto concat_t::operator()(Xs&& xs, Ys&& ys) const {
0032 using M = typename hana::tag_of<Xs>::type;
0033 using Concat = BOOST_HANA_DISPATCH_IF(concat_impl<M>,
0034 hana::MonadPlus<M>::value &&
0035 std::is_same<typename hana::tag_of<Ys>::type, M>::value
0036 );
0037
0038 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0039 static_assert(std::is_same<typename hana::tag_of<Ys>::type, M>::value,
0040 "hana::concat(xs, ys) requires 'xs' and 'ys' to have the same tag");
0041
0042 static_assert(hana::MonadPlus<M>::value,
0043 "hana::concat(xs, ys) requires 'xs' and 'ys' to be MonadPlus");
0044 #endif
0045
0046 return Concat::apply(static_cast<Xs&&>(xs), static_cast<Ys&&>(ys));
0047 }
0048
0049
0050 template <typename M, bool condition>
0051 struct concat_impl<M, when<condition>> : default_ {
0052 template <typename ...Args>
0053 static constexpr auto apply(Args&& ...) = delete;
0054 };
0055
0056 template <typename S>
0057 struct concat_impl<S, when<Sequence<S>::value>> {
0058 template <typename Xs, typename Ys, std::size_t ...xi, std::size_t ...yi>
0059 static constexpr auto
0060 concat_helper(Xs&& xs, Ys&& ys, std::index_sequence<xi...>,
0061 std::index_sequence<yi...>)
0062 {
0063 return hana::make<S>(
0064 hana::at_c<xi>(static_cast<Xs&&>(xs))...,
0065 hana::at_c<yi>(static_cast<Ys&&>(ys))...
0066 );
0067 }
0068
0069 template <typename Xs, typename Ys>
0070 static constexpr auto apply(Xs&& xs, Ys&& ys) {
0071 constexpr std::size_t xi = decltype(hana::length(xs))::value;
0072 constexpr std::size_t yi = decltype(hana::length(ys))::value;
0073 return concat_helper(static_cast<Xs&&>(xs), static_cast<Ys&&>(ys),
0074 std::make_index_sequence<xi>{},
0075 std::make_index_sequence<yi>{});
0076 }
0077 };
0078 }}
0079
0080 #endif