MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Tuples.h
Go to the documentation of this file.
1/** @noop License Comment
2 * @file
3 * @copyright
4 * This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5 * If a copy of the MPL was not distributed with this file You can obtain one at
6 * https://mozilla.org/MPL/2.0/
7 *
8 * @author David Mórász
9 * @date 2025
10 */
11
12#pragma once
13
14#include "CoreMinimal.h"
15
16/** Templating utilities for manipulating `TTuple`s */
17namespace Mcro::Tuples
18{
19 /** Compose one tuple out of the elements of another tuple based on the input index parameter pack */
20 template <typename Tuple, size_t... Indices>
21 using TComposeFrom = TTuple<typename TTupleElement<Indices, Tuple>::Type...>;
22
23 /** @copydoc TSkip */
24 template <size_t Count, typename Tuple>
25 requires (TTupleArity<Tuple>::Value >= Count)
27 {
28 template <size_t... Indices>
29 static consteval TComposeFrom<Tuple, (Indices + Count)...> Compose(std::index_sequence<Indices...>&&);
30
31 using Type = decltype(
32 Compose(std::make_index_sequence<TTupleArity<Tuple>::Value - Count>{})
33 );
34 };
35
36 /** Skip the first `Count` elements of the input tuple */
37 template <size_t Count, typename Tuple>
39
40 /** @copydoc TTrimEnd */
41 template <size_t Count, typename Tuple>
42 requires (TTupleArity<Tuple>::Value >= Count)
44 {
45 template <size_t... Indices>
46 static consteval TComposeFrom<Tuple, Indices...> Compose(std::index_sequence<Indices...>&&);
47
48 using Type = decltype(
49 Compose(std::make_index_sequence<TTupleArity<Tuple>::Value - Count>{})
50 );
51 };
52
53 /** Disregard the last `Count` elements of the input tuple */
54 template <size_t Count, typename Tuple>
56
57 /** @copydoc TTake */
58 template <size_t Count, typename Tuple>
59 requires (TTupleArity<Tuple>::Value >= Count)
61 {
62 template <size_t... Indices>
63 static consteval TComposeFrom<Tuple, Indices...> Compose(std::index_sequence<Indices...>&&);
64
65 using Type = decltype(
66 Compose(std::make_index_sequence<Count>{})
67 );
68 };
69
70 /** Take only the first `Count` elements of the input tuple */
71 template <size_t Count, typename Tuple>
73}
typename TTake_Struct< Count, Tuple >::Type TTake
Definition Tuples.h:72
typename TSkip_Struct< Count, Tuple >::Type TSkip
Definition Tuples.h:38
TTuple< typename TTupleElement< Indices, Tuple >::Type... > TComposeFrom
Definition Tuples.h:21
typename TTrimEnd_Struct< Count, Tuple >::Type TTrimEnd
Definition Tuples.h:55
static consteval TComposeFrom< Tuple,(Indices+Count)... > Compose(std::index_sequence< Indices... > &&)
decltype( Compose(std::make_index_sequence< TTupleArity< Tuple >::Value - Count >{})) Type
Definition Tuples.h:31
static consteval TComposeFrom< Tuple, Indices... > Compose(std::index_sequence< Indices... > &&)
decltype( Compose(std::make_index_sequence< Count >{})) Type
Definition Tuples.h:65
static consteval TComposeFrom< Tuple, Indices... > Compose(std::index_sequence< Indices... > &&)
decltype( Compose(std::make_index_sequence< TTupleArity< Tuple >::Value - Count >{})) Type
Definition Tuples.h:48