3 Adapts `boost::fusion::vector` for use with Hana.
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_VECTOR_HPP
11 #define BOOST_HANA_EXT_BOOST_FUSION_VECTOR_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_vector.hpp>
24 #include <boost/fusion/container/vector.hpp>
25 #include <boost/fusion/container/vector/convert.hpp>
26 #include <boost/fusion/support/tag_of.hpp>
29 #include <type_traits>
33 #ifdef BOOST_HANA_DOXYGEN_INVOKED
34 namespace boost { namespace fusion {
35 //! @ingroup group-ext-fusion
36 //! Adapter for Boost.Fusion vectors.
41 //! A Fusion vector is a model of the `Sequence` concept, and all the
42 //! concepts it refines. That makes it essentially the same as a Hana
43 //! tuple, although the complexity of some operations might differ from
46 //! @include example/ext/boost/fusion/vector.cpp
47 template <typename ...T>
53 BOOST_HANA_NAMESPACE_BEGIN
54 namespace ext { namespace boost { namespace fusion {
59 struct tag_of<T, when<
61 typename ::boost::fusion::traits::tag_of<T>::type,
62 ::boost::fusion::traits::tag_of<
63 ::boost::fusion::vector<>
67 using type = ext::boost::fusion::vector_tag;
72 struct is_fusion_sequence<ext::boost::fusion::vector_tag> {
73 static constexpr bool value = true;
77 //////////////////////////////////////////////////////////////////////////
78 // Iterable (the rest is in detail/common.hpp)
79 //////////////////////////////////////////////////////////////////////////
81 struct drop_front_impl<ext::boost::fusion::vector_tag> {
82 template <std::size_t n, typename Xs, std::size_t ...i>
83 static constexpr auto drop_front_helper(Xs&& xs, std::index_sequence<i...>) {
84 return hana::make<ext::boost::fusion::vector_tag>(
85 hana::at_c<n + i>(static_cast<Xs&&>(xs))...
89 template <typename Xs, typename N>
90 static constexpr auto apply(Xs&& xs, N const&) {
91 constexpr std::size_t n = N::value;
92 constexpr std::size_t len = decltype(hana::length(xs))::value;
93 return drop_front_helper<n>(static_cast<Xs&&>(xs),
94 std::make_index_sequence<(n < len ? len - n : 0)>{});
98 //////////////////////////////////////////////////////////////////////////
100 //////////////////////////////////////////////////////////////////////////
102 struct make_impl<ext::boost::fusion::vector_tag> {
103 template <typename ...Xs>
104 static constexpr auto apply(Xs&& ...xs) {
105 return ::boost::fusion::make_vector(static_cast<Xs&&>(xs)...);
108 BOOST_HANA_NAMESPACE_END
110 #endif // !BOOST_HANA_EXT_BOOST_FUSION_VECTOR_HPP