3 Defines common methods for all Boost.Fusion sequences.
5 @copyright Louis Dionne 2013-2016
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)
10 #ifndef BOOST_HANA_EXT_BOOST_FUSION_DETAIL_COMMON_HPP
11 #define BOOST_HANA_EXT_BOOST_FUSION_DETAIL_COMMON_HPP
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>
22 #include <boost/fusion/sequence/intrinsic/at.hpp>
23 #include <boost/fusion/sequence/intrinsic/empty.hpp>
24 #include <boost/fusion/sequence/intrinsic/size.hpp>
29 BOOST_HANA_NAMESPACE_BEGIN
32 struct is_fusion_sequence {
33 static constexpr bool value = false;
37 //////////////////////////////////////////////////////////////////////////
39 //////////////////////////////////////////////////////////////////////////
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));
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>;
58 //////////////////////////////////////////////////////////////////////////
60 //////////////////////////////////////////////////////////////////////////
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>;
70 //////////////////////////////////////////////////////////////////////////
72 //////////////////////////////////////////////////////////////////////////
74 struct Sequence<S, when<detail::is_fusion_sequence<S>::value>> {
75 static constexpr bool value = true;
77 BOOST_HANA_NAMESPACE_END
79 #endif // !BOOST_HANA_EXT_BOOST_FUSION_DETAIL_COMMON_HPP