KUMI v4.0.0
Flawless Fluorite
Loading...
Searching...
No Matches

◆ reindex

template<kumi::concepts::projection_map auto Projections>
reindex_t<Projections> kumi::reindex {}
inlineconstexprnodiscard

Callable object reindex elements of a Product Type.

This function will issue a compile time error if one of the identifiers is not in t or if any index is outside [0, size_v<T>[ at any given level of the input type.

On record types, this function operates on elements as if they were ordered. The considered order is the order of declaration.

Note
Nothing prevent the number of reordered names to be lesser or greater than t size or the fact they can appear multiple times if it is applied on a named tuple.

Header file

#include <kumi/algorithm/reorder.hpp>

Call Signature

template<identifier auto...Ids, product_type T>
constexpr auto reindex<Ids...>(T && t);
constexpr reindex_t< Projections > reindex
Callable object reindex elements of a Product Type.
Definition reorder.hpp:246
identifier definition class
Definition identifier.hpp:86

Template Parameters

  • Ids Identifiers of the elements to reorder

Parameters

  • t: Product Type to reorder

Return value

  • A potentially nested tuple corresponding to recursive applications of reorder

Helper type

template<kumi::concepts::product_type T, kumi::concepts::projection_map auto Indexes> struct reindex
{
using type = decltype(kumi::reindex<Indexes>(std::declval<T>()));
};
template<kumi::concepts::product_type T, kumi::concepts::projection_map auto Indexes>
using reindex_t = typename kumi::result::reindex<T, Indexes>::type;

Computes the return type of a call to kumi::reindex

Examples

Tuple

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto values = kumi::tuple { 1, 'a', 0.1 };
constexpr auto basic = kumi::indexes(2_c,1_c,0_c);
constexpr auto stack = kumi::projection_map(2_c,1_c,0_c, kumi::indexes(0_c,1_c,2_c));
constexpr auto pairs = kumi::projection_map(kumi::indexes(0_c,0_c), kumi::indexes(1_c,1_c));
std::cout << values << "\n";
std::cout << kumi::reindex<basic>(values) << "\n";
std::cout << kumi::reindex<stack>(values) << "\n";
std::cout << kumi::reindex<pairs>(values) << "\n";
}
consteval auto indexes(Ts...) noexcept
Creates a kumi::projection_map object, deducing the target type from the types of arguments.
Definition projections.hpp:147
KUMI_CUDA projection_map(Ts...) -> projection_map< Ts
kumi::projection_map deduction guide
Definition projections.hpp:131
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33

Record

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto values = kumi::record { "a"_id = 1, "b"_id = 'a', "c"_id = 0.1 };
constexpr auto basic = kumi::indexes(2_c,1_c,0_c);
std::cout << values << "\n";
std::cout << kumi::reindex<basic>(values) << "\n";
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36