fennec
Loading...
Searching...
No Matches
type_sequences.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_LANG_TYPE_SEQUENCES_H
32#define FENNEC_LANG_TYPE_SEQUENCES_H
33
62
63#include <fennec/lang/detail/_type_sequences.h>
64
65namespace fennec
66{
67
68
69template<typename...TypesT> struct type_sequence {};
70
71
72// fennec::first_element ===============================================================================================
73
77template<typename...TypesT> struct first_element : detail::_first_element<TypesT...> {};
78
81template<typename...TypesT> using first_element_t = typename first_element<TypesT...>::type;
82
83
84
85// fennec::nth_element =================================================================================================
86
91template<size_t n, typename...TypesT> struct nth_element : detail::_nth_element<n, 0, TypesT...> {};
92
93template<size_t n, typename...TypesT> using nth_element_t = nth_element<n, TypesT...>::type;
94
95
96
97// fennec::replace_first_element =======================================================================================
98
101template<typename ClassT, typename SubT> struct replace_first_element { };
102
103// Implementation
104template<
105 template<typename, typename...> class ClassT // The Base Template
106, typename SubT, typename OriginT // The Original Type and Type to Substitute
107, typename... RestT> // The Rest of the Parameter Pack
108struct replace_first_element<ClassT<OriginT, RestT...>, SubT> // Specialization
109 { using type = ClassT<SubT, RestT...>; }; // Definition
110
111
112
113// fennec::max_element_size ============================================================================================
114
118template<typename...Ts> struct max_element_size : detail::_max_element_size<0, Ts...> {};
119
123template<typename...Ts> constexpr size_t max_element_size_v = max_element_size<Ts...>::value;
124
125
126
127// fennec::find_element ================================================================================================
128
133template<typename T, typename...Ts> struct find_element : detail::_find_element<0, T, Ts...> {};
134
139template<typename T, typename...Ts> constexpr size_t find_element_v = find_element<T, Ts...>::value;
140
141
142
143// fennec::search_element ==============================================================================================
144
145
150template<template<typename> typename SearchT, typename...TypesT> struct search_element : detail::_search_element<SearchT, TypesT...> {};
151
156template<template<typename> typename SearchT, typename...TypesT> using search_element_t = search_element<SearchT, TypesT...>::type;
157
158
159template<template<typename, typename...> typename, typename, typename...> struct search_element_args;
160
161template<template<typename, typename...> typename SearchT, typename...TypesT, typename...ArgsT>
162struct search_element_args<SearchT, type_sequence<ArgsT...>, TypesT...>
163 : detail::_search_element_args<SearchT, detail::_type_sequence<ArgsT...>, TypesT...> {
164};
165
166
167
168
169// fennec::contains_element ============================================================================================
170
175template<typename T, typename...Ts> struct contains_element : bool_constant<(is_same_v<T, Ts> or ...)> {};
176
181template<typename T, typename...Ts> constexpr bool contains_element_v = contains_element<T, Ts...>::value;
182
183
184
185// fennec::is_unique ===================================================================================================
186
190template<typename...Ts> struct is_unique : false_type {};
191
192// Single type case
193template<typename T> struct is_unique<T> : true_type {};
194
195// Recursion case
196template<typename T, typename...Ts> requires(not is_same_v<T, Ts> && ...)
197struct is_unique<T, Ts...> : is_unique<Ts...> {};
198
202template<typename...Ts> constexpr bool is_unique_v = is_unique<Ts...>::value;
203
204}
205
206
207#endif // FENNEC_LANG_VARIADICS_H
metaprogramming boolean constant
Definition constants.h:95
Checks if the type sequence Ts... contains T
Definition type_sequences.h:175
metaprogramming false constant
Definition constants.h:107
Finds the index of T in Ts, if T is not found, results in sizeof...(Ts)
Definition type_sequences.h:133
Get the first element of a template parameter pack.
Definition type_sequences.h:77
Checks if all types in a type sequence are unique.
Definition type_sequences.h:190
Gets the max value of the size of each type in the sequence, i.e. max(sizeof(Ts).....
Definition type_sequences.h:118
Gets the type of the nth element of the type sequence TypesT...
Definition type_sequences.h:91
Take a Template with a Pack ClassT<ArgsT...> and replace the first ArgT of ArgsT.....
Definition type_sequences.h:101
Find the first element in TypesT... that satisfies SearchT<T>
Definition type_sequences.h:150
metaprogramming true constant
Definition constants.h:101
constexpr bool contains_element_v
Shorthand for contains_element_v<T, Ts...>::value
Definition type_sequences.h:181
constexpr size_t max_element_size_v
Shorthand for max_element_size<Ts...>::value
Definition type_sequences.h:123
constexpr bool is_unique_v
Shorthand for is_unique<Ts...>::value
Definition type_sequences.h:202
typename first_element< TypesT... >::type first_element_t
alias for first_element<TypesT>::type
Definition type_sequences.h:81
constexpr size_t find_element_v
Shorthand for find_element<T, Ts...>::value
Definition type_sequences.h:139
search_element< SearchT, TypesT... >::type search_element_t
Shorthand for search_element_t<T, Ts...>::type
Definition type_sequences.h:156