]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/include/boost/hana/ext/boost/fusion/deque.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / ext / boost / fusion / deque.hpp
1 /*!
2 @file
3 Adapts `boost::fusion::deque` for use with Hana.
4
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)
8 */
9
10 #ifndef BOOST_HANA_EXT_BOOST_FUSION_DEQUE_HPP
11 #define BOOST_HANA_EXT_BOOST_FUSION_DEQUE_HPP
12
13 #include <boost/hana/at.hpp>
14 #include <boost/hana/core/when.hpp>
15 #include <boost/hana/config.hpp>
16 #include <boost/hana/ext/boost/fusion/detail/common.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/length.hpp>
21
22 #include <boost/fusion/container/deque.hpp>
23 #include <boost/fusion/container/generation/make_deque.hpp>
24 #include <boost/fusion/support/tag_of.hpp>
25
26 #include <cstddef>
27 #include <type_traits>
28 #include <utility>
29
30
31 #ifdef BOOST_HANA_DOXYGEN_INVOKED
32 namespace boost { namespace fusion {
33 //! @ingroup group-ext-fusion
34 //! Adapter for Boost.Fusion deques.
35 //!
36 //!
37 //! Modeled concepts
38 //! ----------------
39 //! A Fusion deque is a model of the `Sequence` concept, and all the
40 //! concepts it refines. That makes it essentially the same as a Hana
41 //! tuple, although the complexity of some operations might differ from
42 //! that of a tuple.
43 //!
44 //! @include example/ext/boost/fusion/deque.cpp
45 template <typename ...T>
46 struct deque { };
47 }}
48 #endif
49
50
51 BOOST_HANA_NAMESPACE_BEGIN
52 namespace ext { namespace boost { namespace fusion {
53 struct deque_tag;
54 }}}
55
56 template <typename T>
57 struct tag_of<T, when<
58 std::is_same<
59 typename ::boost::fusion::traits::tag_of<T>::type,
60 ::boost::fusion::traits::tag_of<
61 ::boost::fusion::deque<>
62 >::type
63 >::value
64 >> {
65 using type = ext::boost::fusion::deque_tag;
66 };
67
68 namespace detail {
69 template <>
70 struct is_fusion_sequence<ext::boost::fusion::deque_tag> {
71 static constexpr bool value = true;
72 };
73 }
74
75 //////////////////////////////////////////////////////////////////////////
76 // Iterable (the rest is in detail/common.hpp)
77 //////////////////////////////////////////////////////////////////////////
78 template <>
79 struct drop_front_impl<ext::boost::fusion::deque_tag> {
80 template <std::size_t n, typename Xs, std::size_t ...i>
81 static constexpr auto drop_front_helper(Xs&& xs, std::index_sequence<i...>) {
82 return hana::make<ext::boost::fusion::deque_tag>(
83 hana::at_c<n + i>(static_cast<Xs&&>(xs))...
84 );
85 }
86
87 template <typename Xs, typename N>
88 static constexpr auto apply(Xs&& xs, N const&) {
89 constexpr std::size_t n = N::value;
90 constexpr std::size_t len = decltype(hana::length(xs))::value;
91 return drop_front_helper<n>(static_cast<Xs&&>(xs),
92 std::make_index_sequence<(n < len ? len - n : 0)>{});
93 }
94 };
95
96 //////////////////////////////////////////////////////////////////////////
97 // Sequence
98 //////////////////////////////////////////////////////////////////////////
99 template <>
100 struct make_impl<ext::boost::fusion::deque_tag> {
101 template <typename ...Xs>
102 static constexpr auto apply(Xs&& ...xs) {
103 return ::boost::fusion::make_deque(static_cast<Xs&&>(xs)...);
104 }
105 };
106 BOOST_HANA_NAMESPACE_END
107
108 #endif // !BOOST_HANA_EXT_BOOST_FUSION_DEQUE_HPP