|
|
|||
File indexing completed on 2025-12-15 09:53:05
0001 /*! 0002 @file 0003 Forward declares `boost::hana::tuple`. 0004 0005 Copyright Louis Dionne 2013-2022 0006 Distributed under the Boost Software License, Version 1.0. 0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 0008 */ 0009 0010 #ifndef BOOST_HANA_FWD_TUPLE_HPP 0011 #define BOOST_HANA_FWD_TUPLE_HPP 0012 0013 #include <boost/hana/config.hpp> 0014 #include <boost/hana/fwd/core/make.hpp> 0015 #include <boost/hana/fwd/core/to.hpp> 0016 #include <boost/hana/fwd/integral_constant.hpp> 0017 #include <boost/hana/fwd/type.hpp> 0018 0019 0020 namespace boost { namespace hana { 0021 //! @ingroup group-datatypes 0022 //! General purpose index-based heterogeneous sequence with a fixed length. 0023 //! 0024 //! The tuple is the bread and butter for static metaprogramming. 0025 //! Conceptually, it is like a `std::tuple`; it is a container able 0026 //! of holding objects of different types and whose size is fixed at 0027 //! compile-time. However, Hana's tuple provides much more functionality 0028 //! than its `std` counterpart, and it is also much more efficient than 0029 //! all standard library implementations tested so far. 0030 //! 0031 //! Tuples are index-based sequences. If you need an associative 0032 //! sequence with a key-based access, then you should consider 0033 //! `hana::map` or `hana::set` instead. 0034 //! 0035 //! @note 0036 //! When you use a container, remember not to make assumptions about its 0037 //! representation, unless the documentation gives you those guarantees. 0038 //! More details [in the tutorial](@ref tutorial-containers-types). 0039 //! 0040 //! 0041 //! Modeled concepts 0042 //! ---------------- 0043 //! `Sequence`, and all the concepts it refines 0044 //! 0045 //! 0046 //! Provided operators 0047 //! ------------------ 0048 //! For convenience, the following operators are provided: 0049 //! @code 0050 //! xs == ys -> equal(xs, ys) 0051 //! xs != ys -> not_equal(xs, ys) 0052 //! 0053 //! xs < ys -> less(xs, ys) 0054 //! xs <= ys -> less_equal(xs, ys) 0055 //! xs > ys -> greater(xs, ys) 0056 //! xs >= ys -> greater_equal(xs, ys) 0057 //! 0058 //! xs | f -> chain(xs, f) 0059 //! 0060 //! xs[n] -> at(xs, n) 0061 //! @endcode 0062 //! 0063 //! 0064 //! Example 0065 //! ------- 0066 //! @include example/tuple/tuple.cpp 0067 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0068 template <typename ...Xn> 0069 struct tuple { 0070 //! Default constructs the `tuple`. Only exists when all the elements 0071 //! of the tuple are default constructible. 0072 constexpr tuple(); 0073 0074 //! Initialize each element of the tuple with the corresponding element 0075 //! from `xn...`. Only exists when all the elements of the tuple are 0076 //! copy-constructible. 0077 //! 0078 //! @note 0079 //! Unlike the corresponding constructor for `std::tuple`, this 0080 //! constructor is not explicit. This allows returning a tuple 0081 //! from a function with the brace-initialization syntax. 0082 constexpr tuple(Xn const& ...xn); 0083 0084 //! Initialize each element of the tuple by perfect-forwarding the 0085 //! corresponding element in `yn...`. Only exists when all the 0086 //! elements of the created tuple are constructible from the 0087 //! corresponding perfect-forwarded value. 0088 //! 0089 //! @note 0090 //! Unlike the corresponding constructor for `std::tuple`, this 0091 //! constructor is not explicit. This allows returning a tuple 0092 //! from a function with the brace-initialization syntax. 0093 template <typename ...Yn> 0094 constexpr tuple(Yn&& ...yn); 0095 0096 //! Copy-initialize a tuple from another tuple. Only exists when all 0097 //! the elements of the constructed tuple are copy-constructible from 0098 //! the corresponding element in the source tuple. 0099 template <typename ...Yn> 0100 constexpr tuple(tuple<Yn...> const& other); 0101 0102 //! Move-initialize a tuple from another tuple. Only exists when all 0103 //! the elements of the constructed tuple are move-constructible from 0104 //! the corresponding element in the source tuple. 0105 template <typename ...Yn> 0106 constexpr tuple(tuple<Yn...>&& other); 0107 0108 //! Assign a tuple to another tuple. Only exists when all the elements 0109 //! of the destination tuple are assignable from the corresponding 0110 //! element in the source tuple. 0111 template <typename ...Yn> 0112 constexpr tuple& operator=(tuple<Yn...> const& other); 0113 0114 //! Move-assign a tuple to another tuple. Only exists when all the 0115 //! elements of the destination tuple are move-assignable from the 0116 //! corresponding element in the source tuple. 0117 template <typename ...Yn> 0118 constexpr tuple& operator=(tuple<Yn...>&& other); 0119 0120 //! Equivalent to `hana::chain`. 0121 template <typename ...T, typename F> 0122 friend constexpr auto operator|(tuple<T...>, F); 0123 0124 //! Equivalent to `hana::equal` 0125 template <typename X, typename Y> 0126 friend constexpr auto operator==(X&& x, Y&& y); 0127 0128 //! Equivalent to `hana::not_equal` 0129 template <typename X, typename Y> 0130 friend constexpr auto operator!=(X&& x, Y&& y); 0131 0132 //! Equivalent to `hana::less` 0133 template <typename X, typename Y> 0134 friend constexpr auto operator<(X&& x, Y&& y); 0135 0136 //! Equivalent to `hana::greater` 0137 template <typename X, typename Y> 0138 friend constexpr auto operator>(X&& x, Y&& y); 0139 0140 //! Equivalent to `hana::less_equal` 0141 template <typename X, typename Y> 0142 friend constexpr auto operator<=(X&& x, Y&& y); 0143 0144 //! Equivalent to `hana::greater_equal` 0145 template <typename X, typename Y> 0146 friend constexpr auto operator>=(X&& x, Y&& y); 0147 0148 //! Equivalent to `hana::at` 0149 template <typename N> 0150 constexpr decltype(auto) operator[](N&& n); 0151 }; 0152 #else 0153 template <typename ...Xn> 0154 struct tuple; 0155 #endif 0156 0157 //! Tag representing `hana::tuple`s. 0158 //! @related tuple 0159 struct tuple_tag { }; 0160 0161 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0162 //! Function object for creating a `tuple`. 0163 //! @relates hana::tuple 0164 //! 0165 //! Given zero or more objects `xs...`, `make<tuple_tag>` returns a new tuple 0166 //! containing those objects. The elements are held by value inside the 0167 //! resulting tuple, and they are hence copied or moved in. This is 0168 //! analogous to `std::make_tuple` for creating Hana tuples. 0169 //! 0170 //! 0171 //! Example 0172 //! ------- 0173 //! @include example/tuple/make.cpp 0174 template <> 0175 constexpr auto make<tuple_tag> = [](auto&& ...xs) { 0176 return tuple<std::decay_t<decltype(xs)>...>{forwarded(xs)...}; 0177 }; 0178 #endif 0179 0180 //! Alias to `make<tuple_tag>`; provided for convenience. 0181 //! @relates hana::tuple 0182 BOOST_HANA_INLINE_VARIABLE constexpr auto make_tuple = make<tuple_tag>; 0183 0184 //! Equivalent to `to<tuple_tag>`; provided for convenience. 0185 //! @relates hana::tuple 0186 BOOST_HANA_INLINE_VARIABLE constexpr auto to_tuple = to<tuple_tag>; 0187 0188 //! Create a tuple specialized for holding `hana::type`s. 0189 //! @relates hana::tuple 0190 //! 0191 //! This is functionally equivalent to `make<tuple_tag>(type_c<T>...)`, except 0192 //! that using `tuple_t` allows the library to perform some compile-time 0193 //! optimizations. Also note that the type of the objects returned by 0194 //! `tuple_t` and an equivalent call to `make<tuple_tag>` may differ. 0195 //! 0196 //! 0197 //! Example 0198 //! ------- 0199 //! @include example/tuple/tuple_t.cpp 0200 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0201 template <typename ...T> 0202 constexpr implementation_defined tuple_t{}; 0203 #else 0204 template <typename ...T> 0205 BOOST_HANA_INLINE_VARIABLE constexpr hana::tuple<hana::type<T>...> tuple_t{}; 0206 #endif 0207 0208 //! Create a tuple specialized for holding `hana::integral_constant`s. 0209 //! @relates hana::tuple 0210 //! 0211 //! This is functionally equivalent to `make<tuple_tag>(integral_c<T, v>...)`, 0212 //! except that using `tuple_c` allows the library to perform some 0213 //! compile-time optimizations. Also note that the type of the objects 0214 //! returned by `tuple_c` and an equivalent call to `make<tuple_tag>` may differ. 0215 //! 0216 //! 0217 //! Example 0218 //! ------- 0219 //! @include example/tuple/tuple_c.cpp 0220 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0221 template <typename T, T ...v> 0222 constexpr implementation_defined tuple_c{}; 0223 #else 0224 template <typename T, T ...v> 0225 BOOST_HANA_INLINE_VARIABLE constexpr hana::tuple<hana::integral_constant<T, v>...> tuple_c{}; 0226 #endif 0227 }} // end namespace boost::hana 0228 0229 #endif // !BOOST_HANA_FWD_TUPLE_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|