File indexing completed on 2025-01-30 09:43:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_FLATTEN_HPP
0011 #define BOOST_HANA_FLATTEN_HPP
0012
0013 #include <boost/hana/fwd/flatten.hpp>
0014
0015 #include <boost/hana/concept/monad.hpp>
0016 #include <boost/hana/concept/sequence.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/core/make.hpp>
0020 #include <boost/hana/detail/unpack_flatten.hpp>
0021 #include <boost/hana/functional/id.hpp>
0022 #include <boost/hana/fwd/chain.hpp>
0023
0024 #include <cstddef>
0025 #include <utility>
0026
0027
0028 namespace boost { namespace hana {
0029
0030 template <typename Xs>
0031 constexpr auto flatten_t::operator()(Xs&& xs) const {
0032 using M = typename hana::tag_of<Xs>::type;
0033 using Flatten = BOOST_HANA_DISPATCH_IF(flatten_impl<M>,
0034 hana::Monad<M>::value
0035 );
0036
0037 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0038 static_assert(hana::Monad<M>::value,
0039 "hana::flatten(xs) requires 'xs' to be a Monad");
0040 #endif
0041
0042 return Flatten::apply(static_cast<Xs&&>(xs));
0043 }
0044
0045
0046 template <typename M, bool condition>
0047 struct flatten_impl<M, when<condition>> : default_ {
0048 template <typename Xs>
0049 static constexpr auto apply(Xs&& xs)
0050 { return hana::chain(static_cast<Xs&&>(xs), hana::id); }
0051 };
0052
0053 template <typename S>
0054 struct flatten_impl<S, when<Sequence<S>::value>> {
0055 template <typename Xs>
0056 static constexpr auto apply(Xs&& xs) {
0057 return detail::unpack_flatten(static_cast<Xs&&>(xs), hana::make<S>);
0058 }
0059 };
0060 }}
0061
0062 #endif