| 1 | /*! |
| 2 | @file |
| 3 | Defines common methods for all Boost.Fusion sequences. |
| 4 | |
| 5 | Copyright Louis Dionne 2013-2022 |
| 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_EXT_BOOST_FUSION_DETAIL_COMMON_HPP |
| 11 | #define BOOST_HANA_EXT_BOOST_FUSION_DETAIL_COMMON_HPP |
| 12 | |
| 13 | #include <boost/hana/bool.hpp> |
| 14 | #include <boost/hana/config.hpp> |
| 15 | #include <boost/hana/core/when.hpp> |
| 16 | #include <boost/hana/fwd/at.hpp> |
| 17 | #include <boost/hana/fwd/concept/sequence.hpp> |
| 18 | #include <boost/hana/fwd/is_empty.hpp> |
| 19 | #include <boost/hana/fwd/length.hpp> |
| 20 | #include <boost/hana/integral_constant.hpp> |
| 21 | |
| 22 | #include <boost/fusion/sequence/intrinsic/at.hpp> |
| 23 | #include <boost/fusion/sequence/intrinsic/empty.hpp> |
| 24 | #include <boost/fusion/sequence/intrinsic/size.hpp> |
| 25 | |
| 26 | #include <cstddef> |
| 27 | |
| 28 | |
| 29 | namespace boost { namespace hana { |
| 30 | namespace detail { |
| 31 | template <typename T> |
| 32 | struct is_fusion_sequence { |
| 33 | static constexpr bool value = false; |
| 34 | }; |
| 35 | } |
| 36 | |
| 37 | ////////////////////////////////////////////////////////////////////////// |
| 38 | // Iterable |
| 39 | ////////////////////////////////////////////////////////////////////////// |
| 40 | template <typename S> |
| 41 | struct at_impl<S, when<detail::is_fusion_sequence<S>::value>> { |
| 42 | template <typename Xs, typename N> |
| 43 | static constexpr decltype(auto) apply(Xs&& xs, N const&) { |
| 44 | constexpr std::size_t n = N::value; |
| 45 | return boost::fusion::at_c<n>(static_cast<Xs&&>(xs)); |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | template <typename S> |
| 50 | struct is_empty_impl<S, when<detail::is_fusion_sequence<S>::value>> { |
| 51 | template <typename Xs> |
| 52 | static constexpr auto apply(Xs&& xs) { |
| 53 | using Empty = decltype(boost::fusion::empty(xs)); |
| 54 | return hana::bool_c<Empty::value>; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | ////////////////////////////////////////////////////////////////////////// |
| 59 | // Foldable |
| 60 | ////////////////////////////////////////////////////////////////////////// |
| 61 | template <typename S> |
| 62 | struct length_impl<S, when<detail::is_fusion_sequence<S>::value>> { |
| 63 | template <typename Xs> |
| 64 | static constexpr auto apply(Xs const&) { |
| 65 | using Size = typename boost::fusion::result_of::size<Xs>::type; |
| 66 | return hana::size_c<Size::value>; |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | ////////////////////////////////////////////////////////////////////////// |
| 71 | // Sequence |
| 72 | ////////////////////////////////////////////////////////////////////////// |
| 73 | template <typename S> |
| 74 | struct Sequence<S, when<detail::is_fusion_sequence<S>::value>> { |
| 75 | static constexpr bool value = true; |
| 76 | }; |
| 77 | }} // end namespace boost::hana |
| 78 | |
| 79 | #endif // !BOOST_HANA_EXT_BOOST_FUSION_DETAIL_COMMON_HPP |
| 80 | |