3 Forward declares `boost::hana::tuple`.
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_FWD_TUPLE_HPP
11 #define BOOST_HANA_FWD_TUPLE_HPP
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>
20 BOOST_HANA_NAMESPACE_BEGIN
21 //! @ingroup group-datatypes
22 //! General purpose index-based heterogeneous sequence with a fixed length.
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.
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.
38 //! `Sequence`, and all the concepts it refines
41 //! Provided operators
42 //! ------------------
43 //! For convenience, the following operators are provided:
45 //! xs == ys -> equal(xs, ys)
46 //! xs != ys -> not_equal(xs, ys)
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)
53 //! xs | f -> chain(xs, f)
55 //! xs[n] -> at(xs, n)
61 //! @include example/tuple/tuple.cpp
62 #ifdef BOOST_HANA_DOXYGEN_INVOKED
63 template <typename ...Xn>
65 //! Default constructs the `tuple`. Only exists when all the elements
66 //! of the tuple are default constructible.
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.
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);
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.
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);
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);
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);
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);
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);
115 //! Equivalent to `hana::chain`.
116 template <typename ...T, typename F>
117 friend constexpr auto operator|(tuple<T...>, F);
119 //! Equivalent to `hana::equal`
120 template <typename X, typename Y>
121 friend constexpr auto operator==(X&& x, Y&& y);
123 //! Equivalent to `hana::not_equal`
124 template <typename X, typename Y>
125 friend constexpr auto operator!=(X&& x, Y&& y);
127 //! Equivalent to `hana::less`
128 template <typename X, typename Y>
129 friend constexpr auto operator<(X&& x, Y&& y);
131 //! Equivalent to `hana::greater`
132 template <typename X, typename Y>
133 friend constexpr auto operator>(X&& x, Y&& y);
135 //! Equivalent to `hana::less_equal`
136 template <typename X, typename Y>
137 friend constexpr auto operator<=(X&& x, Y&& y);
139 //! Equivalent to `hana::greater_equal`
140 template <typename X, typename Y>
141 friend constexpr auto operator>=(X&& x, Y&& y);
143 //! Equivalent to `hana::at`
144 template <typename N>
145 constexpr decltype(auto) operator[](N&& n);
148 template <typename ...Xn>
152 //! Tag representing `hana::tuple`s.
154 struct tuple_tag { };
156 #ifdef BOOST_HANA_DOXYGEN_INVOKED
157 //! Function object for creating a `tuple`.
158 //! @relates hana::tuple
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.
168 //! @include example/tuple/make.cpp
170 constexpr auto make<tuple_tag> = [](auto&& ...xs) {
171 return tuple<std::decay_t<decltype(xs)>...>{forwarded(xs)...};
175 //! Alias to `make<tuple_tag>`; provided for convenience.
176 //! @relates hana::tuple
177 constexpr auto make_tuple = make<tuple_tag>;
179 //! Equivalent to `to<tuple_tag>`; provided for convenience.
180 //! @relates hana::tuple
181 constexpr auto to_tuple = to<tuple_tag>;
183 //! Create a tuple specialized for holding `hana::type`s.
184 //! @relates hana::tuple
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.
194 //! @include example/tuple/tuple_t.cpp
195 #ifdef BOOST_HANA_DOXYGEN_INVOKED
196 template <typename ...T>
197 constexpr implementation_defined tuple_t{};
199 template <typename ...T>
200 constexpr hana::tuple<hana::type<T>...> tuple_t{};
203 //! Create a tuple specialized for holding `hana::integral_constant`s.
204 //! @relates hana::tuple
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.
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{};
219 template <typename T, T ...v>
220 constexpr hana::tuple<hana::integral_constant<T, v>...> tuple_c{};
222 BOOST_HANA_NAMESPACE_END
224 #endif // !BOOST_HANA_FWD_TUPLE_HPP