swift
tuple.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2021 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #ifndef SWIFT_MISC_TUPLE_H
7 #define SWIFT_MISC_TUPLE_H
8 
9 #include <utility>
10 
12 namespace swift::misc::private_ns
13 {
14  /*
15  * Own minimal implementation of std::tuple with very limited functionality.
16  * Only used to reduce compile time for the metaclass system.
17  */
18 
19  template <size_t I, typename T>
20  struct tuple_part
21  {
22  T value;
23  };
24 
25  template <typename...>
26  struct tuple_impl;
27 
28  template <size_t... Is, typename... Ts>
29  struct tuple_impl<std::index_sequence<Is...>, Ts...> : public tuple_part<Is, Ts>...
30  {
31  template <typename F>
32  void for_each(F &&visitor) const
33  {
34  (static_cast<void>(visitor(static_cast<const tuple_part<Is, Ts> &>(*this).value)), ...);
35  }
36  };
37 
38  template <typename... Ts>
39  struct tuple : public tuple_impl<std::make_index_sequence<sizeof...(Ts)>, Ts...>
40  {};
41 } // namespace swift::misc::private_ns
43 
44 #endif // SWIFT_MISC_TUPLE_H