3 Adapts `boost::fusion::list` for use with Hana.
5 @copyright Louis Dionne 2013-2017
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_LIST_HPP
11 #define BOOST_HANA_EXT_BOOST_FUSION_LIST_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
15 #include <boost/hana/ext/boost/fusion/detail/common.hpp>
16 #include <boost/hana/fwd/at.hpp>
17 #include <boost/hana/fwd/core/make.hpp>
18 #include <boost/hana/fwd/core/tag_of.hpp>
19 #include <boost/hana/fwd/drop_front.hpp>
20 #include <boost/hana/fwd/length.hpp>
22 #include <boost/fusion/algorithm/transformation/pop_front.hpp>
23 #include <boost/fusion/container/generation/make_list.hpp>
24 #include <boost/fusion/container/list.hpp>
25 #include <boost/fusion/container/list/convert.hpp>
26 #include <boost/fusion/support/tag_of.hpp>
27 #include <boost/version.hpp>
30 #include <type_traits>
34 #ifdef BOOST_HANA_DOXYGEN_INVOKED
35 namespace boost { namespace fusion {
36 //! @ingroup group-ext-fusion
37 //! Adapter for Boost.Fusion lists.
42 //! A Fusion list is a model of the `Sequence` concept, and all the
43 //! concepts it refines. That makes it essentially the same as a Hana
44 //! tuple, although the complexity of some operations might differ from
47 //! @include example/ext/boost/fusion/list.cpp
48 template <typename ...T>
54 BOOST_HANA_NAMESPACE_BEGIN
55 namespace ext { namespace boost { namespace fusion {
60 struct tag_of<T, when<
62 typename ::boost::fusion::traits::tag_of<T>::type,
63 ::boost::fusion::traits::tag_of<
64 ::boost::fusion::list<>
68 using type = ext::boost::fusion::list_tag;
73 struct is_fusion_sequence<ext::boost::fusion::list_tag> {
74 static constexpr bool value = true;
78 //////////////////////////////////////////////////////////////////////////
79 // Iterable (the rest is in detail/common.hpp)
80 //////////////////////////////////////////////////////////////////////////
82 struct drop_front_impl<ext::boost::fusion::list_tag> {
83 template <std::size_t n, typename Xs, std::size_t ...i>
84 static constexpr auto drop_front_helper(Xs&& xs, std::index_sequence<i...>) {
85 return hana::make<ext::boost::fusion::list_tag>(
86 hana::at_c<n + i>(static_cast<Xs&&>(xs))...
90 template <typename Xs, typename N>
91 static constexpr auto apply(Xs&& xs, N const&) {
92 constexpr std::size_t n = N::value;
93 constexpr std::size_t len = decltype(hana::length(xs))::value;
94 return drop_front_helper<n>(static_cast<Xs&&>(xs),
95 std::make_index_sequence<(n < len ? len - n : 0)>{});
99 //////////////////////////////////////////////////////////////////////////
101 //////////////////////////////////////////////////////////////////////////
103 struct make_impl<ext::boost::fusion::list_tag> {
104 template <typename ...Xs>
105 static constexpr auto apply(Xs&& ...xs) {
106 return ::boost::fusion::make_list(static_cast<Xs&&>(xs)...);
109 BOOST_HANA_NAMESPACE_END
111 #endif // !BOOST_HANA_EXT_BOOST_FUSION_LIST_HPP