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