fennec
Loading...
Searching...
No Matches
tuple.h
Go to the documentation of this file.
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
30
31#ifndef FENNEC_CONTAINERS_TUPLE_H
32#define FENNEC_CONTAINERS_TUPLE_H
33
34#include <fennec/containers/detail/_tuple.h>
36
37namespace fennec
38{
39
40// TODO: Document
41
60template<typename...TypesT> struct tuple;
61
62
63template<size_t i, typename...TypesT>
64constexpr typename tuple<TypesT...>::template elem_t<i>& get(tuple<TypesT...>& x) {
65 using elem_t = typename tuple<TypesT...>::template elem_t<i>;
66 auto& it = *static_cast<detail::_tuple_leaf<i, elem_t>*>(&x);
67 return it.value;
68}
69
70template<size_t i, typename...TypesT>
71constexpr const typename tuple<TypesT...>::template elem_t<i>& get(const tuple<TypesT...>& x) {
72 using elem_t = typename tuple<TypesT...>::template elem_t<i>;
73 const auto& it = *static_cast<const detail::_tuple_leaf<i, elem_t>*>(&x);
74 return it.value;
75}
76
77
78template<typename ...TypesT>
79struct tuple : public detail::_tuple<make_index_metasequence_t<sizeof...(TypesT)>, TypesT...>
80{
81 using base_t = detail::_tuple<make_index_metasequence_t<sizeof...(TypesT)>, TypesT...>;
82
83 template<size_t i>
84 using elem_t = typename nth_element<i, TypesT...>::type;
85
86 static constexpr size_t size = sizeof...(TypesT);
87
88 template<typename...ArgsT>
89 tuple(ArgsT&&...args)
90 : base_t(fennec::forward<ArgsT>(args)...) {
91 }
92
93 tuple(const tuple& cpy)
94 : base_t(cpy) {
95 }
96
97 tuple(tuple&& cpy)
98 : base_t(cpy) {
99 }
100};
101
102// This is needed for
103template<typename...TypesT>
104tuple(TypesT...) -> tuple<TypesT...>;
105
106}
107
108#endif // FENNEC_CONTAINERS_TUPLE_H
typename make_index_metasequence< N >::type make_index_metasequence_t
shorthand for typename make_index_metasequence<N>::type
Definition metasequences.h:189
Gets the type of the nth element of the type sequence TypesT...
Definition type_sequences.h:91
Tuple, holds a collection of values of different types.
Definition tuple.h:80
Type Sequences