< prev index next >

src/hotspot/share/utilities/tuple.hpp

Print this page

 1 /*
 2 * Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4 *
 5 * This code is free software; you can redistribute it and/or modify it
 6 * under the terms of the GNU General Public License version 2 only, as
 7 * published by the Free Software Foundation.
 8 *
 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24 
25 #ifndef SHARE_UTILITIES_TUPLE_HPP
26 #define SHARE_UTILITIES_TUPLE_HPP
27 
28 #include "cppstdlib/type_traits.hpp"
29 
30 template <class... Ts>
31 class Tuple;
32 
33 template <>
34 class Tuple<> {};
35 
36 template <class T, class... Ts>
37 class Tuple<T, Ts...> {
38 private:
39   T _first;
40   Tuple<Ts...> _remaining;
41 
42 public:


43   constexpr Tuple(const T& first, const Ts&... remaining) noexcept
44     : _first(first), _remaining(remaining...) {}
45 
46   template <std::size_t I, std::enable_if_t<(I > 0), int> = 0>
47   constexpr const auto& get() const noexcept {
48     return _remaining.template get<I - 1>();
49   };
50 
51   template <std::size_t I, std::enable_if_t<I == 0, int> = 0>
52   constexpr const T& get() const noexcept {
53     return _first;
54   }
55 };
56 
57 #endif // SHARE_UTILITIES_TUPLE_HPP

 1 /*
 2 * Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved.
 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4 *
 5 * This code is free software; you can redistribute it and/or modify it
 6 * under the terms of the GNU General Public License version 2 only, as
 7 * published by the Free Software Foundation.
 8 *
 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24 
25 #ifndef SHARE_UTILITIES_TUPLE_HPP
26 #define SHARE_UTILITIES_TUPLE_HPP
27 
28 #include "cppstdlib/type_traits.hpp"
29 
30 template <class... Ts>
31 class Tuple;
32 
33 template <>
34 class Tuple<> {};
35 
36 template <class T, class... Ts>
37 class Tuple<T, Ts...> {
38 private:
39   T _first;
40   Tuple<Ts...> _remaining;
41 
42 public:
43   constexpr explicit Tuple() noexcept : _first(), _remaining() {}
44 
45   constexpr Tuple(const T& first, const Ts&... remaining) noexcept
46     : _first(first), _remaining(remaining...) {}
47 
48   template <std::size_t I, std::enable_if_t<(I > 0), int> = 0>
49   constexpr const auto& get() const noexcept {
50     return _remaining.template get<I - 1>();
51   };
52 
53   template <std::size_t I, std::enable_if_t<I == 0, int> = 0>
54   constexpr const T& get() const noexcept {
55     return _first;
56   }
57 };
58 
59 #endif // SHARE_UTILITIES_TUPLE_HPP
< prev index next >