MySQL 8.3.0
Source Code Documentation
ut0tuple.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2020, 2023, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/ut0tuple.h
28 std::tuple helper utilities. */
29
30#ifndef ut0tuple_h
31#define ut0tuple_h
32
33#include <tuple>
34#include <utility>
35
36// std::index_sequence can only generate a sequence of indices starting from 0.
37// This utility, index_sequence_with_offset, enables us to generate a
38// sequence of indices with the offset.
39//
40// E.g.
41// index_sequence_with_offset_t<10, std::make_index_sequence<5>{}>
42// generates a sequence of {10, 11, 12, 13, 14} integers.
43template <std::size_t N, typename Seq>
45
46template <std::size_t N, std::size_t... Ints>
47struct index_sequence_with_offset<N, std::index_sequence<Ints...>> {
48 using type = std::index_sequence<Ints + N...>;
49};
50
51// Helper alias which saves us from typing ::type
52template <std::size_t N, typename Seq>
55
56namespace detail {
57template <typename Tuple, size_t... Is>
58constexpr auto select_from_tuple_impl(Tuple &&t, std::index_sequence<Is...>) {
59 return std::make_tuple(std::get<Is>(t)...);
60}
61} // namespace detail
62
63// Utility function which returns a new tuple which is a [Begin, End> subset of
64// given tuple.
65// E.g.
66// auto t = select_from_tuple<1, 3>(make_tuple(1, 2, 3, 4, 5));
67// assert(t == make_tuple(2, 3));
68template <size_t Begin, size_t End, typename Tuple>
69constexpr auto select_from_tuple(Tuple &&t) {
71 std::forward<Tuple>(t),
73 std::make_index_sequence<End - Begin>>{});
74}
75
76#endif /* ut0tuple_h */
std::atomic< Type > N
Definition: ut0counter.h:224
Definition: ut0tuple.h:56
constexpr auto select_from_tuple_impl(Tuple &&t, std::index_sequence< Is... >)
Definition: ut0tuple.h:58
Definition: varlen_sort.h:174
std::index_sequence< Ints+N... > type
Definition: ut0tuple.h:48
Definition: ut0tuple.h:44
constexpr auto select_from_tuple(Tuple &&t)
Definition: ut0tuple.h:69
typename index_sequence_with_offset< N, Seq >::type index_sequence_with_offset_t
Definition: ut0tuple.h:54