]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/include/boost/hana/fwd/tuple.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / fwd / tuple.hpp
1 /*!
2 @file
3 Forward declares `boost::hana::tuple`.
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_FWD_TUPLE_HPP
11 #define BOOST_HANA_FWD_TUPLE_HPP
12
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/fwd/core/make.hpp>
15 #include <boost/hana/fwd/core/to.hpp>
16 #include <boost/hana/fwd/integral_constant.hpp>
17 #include <boost/hana/fwd/type.hpp>
18
19
20 BOOST_HANA_NAMESPACE_BEGIN
21 //! @ingroup group-datatypes
22 //! General purpose index-based heterogeneous sequence with a fixed length.
23 //!
24 //! The tuple is the bread and butter for static metaprogramming.
25 //! Conceptually, it is like a `std::tuple`; it is a container able
26 //! of holding objects of different types and whose size is fixed at
27 //! compile-time. However, Hana's tuple provides much more functionality
28 //! than its `std` counterpart, and it is also much more efficient than
29 //! all standard library implementations tested so far.
30 //!
31 //! Tuples are index-based sequences. If you need an associative
32 //! sequence with a key-based access, then you should consider
33 //! `hana::map` or `hana::set` instead.
34 //!
35 //!
36 //! Modeled concepts
37 //! ----------------
38 //! `Sequence`, and all the concepts it refines
39 //!
40 //!
41 //! Provided operators
42 //! ------------------
43 //! For convenience, the following operators are provided:
44 //! @code
45 //! xs == ys -> equal(xs, ys)
46 //! xs != ys -> not_equal(xs, ys)
47 //!
48 //! xs < ys -> less(xs, ys)
49 //! xs <= ys -> less_equal(xs, ys)
50 //! xs > ys -> greater(xs, ys)
51 //! xs >= ys -> greater_equal(xs, ys)
52 //!
53 //! xs | f -> chain(xs, f)
54 //!
55 //! xs[n] -> at(xs, n)
56 //! @endcode
57 //!
58 //!
59 //! Example
60 //! -------
61 //! @include example/tuple/tuple.cpp
62 #ifdef BOOST_HANA_DOXYGEN_INVOKED
63 template <typename ...Xn>
64 struct tuple {
65 //! Default constructs the `tuple`. Only exists when all the elements
66 //! of the tuple are default constructible.
67 constexpr tuple();
68
69 //! Initialize each element of the tuple with the corresponding element
70 //! from `xn...`. Only exists when all the elements of the tuple are
71 //! copy-constructible.
72 //!
73 //! @note
74 //! Unlike the corresponding constructor for `std::tuple`, this
75 //! constructor is not explicit. This allows returning a tuple
76 //! from a function with the brace-initialization syntax.
77 constexpr tuple(Xn const& ...xn);
78
79 //! Initialize each element of the tuple by perfect-forwarding the
80 //! corresponding element in `yn...`. Only exists when all the
81 //! elements of the created tuple are constructible from the
82 //! corresponding perfect-forwarded value.
83 //!
84 //! @note
85 //! Unlike the corresponding constructor for `std::tuple`, this
86 //! constructor is not explicit. This allows returning a tuple
87 //! from a function with the brace-initialization syntax.
88 template <typename ...Yn>
89 constexpr tuple(Yn&& ...yn);
90
91 //! Copy-initialize a tuple from another tuple. Only exists when all
92 //! the elements of the constructed tuple are copy-constructible from
93 //! the corresponding element in the source tuple.
94 template <typename ...Yn>
95 constexpr tuple(tuple<Yn...> const& other);
96
97 //! Move-initialize a tuple from another tuple. Only exists when all
98 //! the elements of the constructed tuple are move-constructible from
99 //! the corresponding element in the source tuple.
100 template <typename ...Yn>
101 constexpr tuple(tuple<Yn...>&& other);
102
103 //! Assign a tuple to another tuple. Only exists when all the elements
104 //! of the destination tuple are assignable from the corresponding
105 //! element in the source tuple.
106 template <typename ...Yn>
107 constexpr tuple& operator=(tuple<Yn...> const& other);
108
109 //! Move-assign a tuple to another tuple. Only exists when all the
110 //! elements of the destination tuple are move-assignable from the
111 //! corresponding element in the source tuple.
112 template <typename ...Yn>
113 constexpr tuple& operator=(tuple<Yn...>&& other);
114
115 //! Equivalent to `hana::chain`.
116 template <typename ...T, typename F>
117 friend constexpr auto operator|(tuple<T...>, F);
118
119 //! Equivalent to `hana::equal`
120 template <typename X, typename Y>
121 friend constexpr auto operator==(X&& x, Y&& y);
122
123 //! Equivalent to `hana::not_equal`
124 template <typename X, typename Y>
125 friend constexpr auto operator!=(X&& x, Y&& y);
126
127 //! Equivalent to `hana::less`
128 template <typename X, typename Y>
129 friend constexpr auto operator<(X&& x, Y&& y);
130
131 //! Equivalent to `hana::greater`
132 template <typename X, typename Y>
133 friend constexpr auto operator>(X&& x, Y&& y);
134
135 //! Equivalent to `hana::less_equal`
136 template <typename X, typename Y>
137 friend constexpr auto operator<=(X&& x, Y&& y);
138
139 //! Equivalent to `hana::greater_equal`
140 template <typename X, typename Y>
141 friend constexpr auto operator>=(X&& x, Y&& y);
142
143 //! Equivalent to `hana::at`
144 template <typename N>
145 constexpr decltype(auto) operator[](N&& n);
146 };
147 #else
148 template <typename ...Xn>
149 struct tuple;
150 #endif
151
152 //! Tag representing `hana::tuple`s.
153 //! @related tuple
154 struct tuple_tag { };
155
156 #ifdef BOOST_HANA_DOXYGEN_INVOKED
157 //! Function object for creating a `tuple`.
158 //! @relates hana::tuple
159 //!
160 //! Given zero or more objects `xs...`, `make<tuple_tag>` returns a new tuple
161 //! containing those objects. The elements are held by value inside the
162 //! resulting tuple, and they are hence copied or moved in. This is
163 //! analogous to `std::make_tuple` for creating Hana tuples.
164 //!
165 //!
166 //! Example
167 //! -------
168 //! @include example/tuple/make.cpp
169 template <>
170 constexpr auto make<tuple_tag> = [](auto&& ...xs) {
171 return tuple<std::decay_t<decltype(xs)>...>{forwarded(xs)...};
172 };
173 #endif
174
175 //! Alias to `make<tuple_tag>`; provided for convenience.
176 //! @relates hana::tuple
177 constexpr auto make_tuple = make<tuple_tag>;
178
179 //! Equivalent to `to<tuple_tag>`; provided for convenience.
180 //! @relates hana::tuple
181 constexpr auto to_tuple = to<tuple_tag>;
182
183 //! Create a tuple specialized for holding `hana::type`s.
184 //! @relates hana::tuple
185 //!
186 //! This is functionally equivalent to `make<tuple_tag>(type_c<T>...)`, except
187 //! that using `tuple_t` allows the library to perform some compile-time
188 //! optimizations. Also note that the type of the objects returned by
189 //! `tuple_t` and an equivalent call to `make<tuple_tag>` may differ.
190 //!
191 //!
192 //! Example
193 //! -------
194 //! @include example/tuple/tuple_t.cpp
195 #ifdef BOOST_HANA_DOXYGEN_INVOKED
196 template <typename ...T>
197 constexpr implementation_defined tuple_t{};
198 #else
199 template <typename ...T>
200 constexpr hana::tuple<hana::type<T>...> tuple_t{};
201 #endif
202
203 //! Create a tuple specialized for holding `hana::integral_constant`s.
204 //! @relates hana::tuple
205 //!
206 //! This is functionally equivalent to `make<tuple_tag>(integral_c<T, v>...)`,
207 //! except that using `tuple_c` allows the library to perform some
208 //! compile-time optimizations. Also note that the type of the objects
209 //! returned by `tuple_c` and an equivalent call to `make<tuple_tag>` may differ.
210 //!
211 //!
212 //! Example
213 //! -------
214 //! @include example/tuple/tuple_c.cpp
215 #ifdef BOOST_HANA_DOXYGEN_INVOKED
216 template <typename T, T ...v>
217 constexpr implementation_defined tuple_c{};
218 #else
219 template <typename T, T ...v>
220 constexpr hana::tuple<hana::integral_constant<T, v>...> tuple_c{};
221 #endif
222 BOOST_HANA_NAMESPACE_END
223
224 #endif // !BOOST_HANA_FWD_TUPLE_HPP