KUMI v3.1.0
Exquisite Epidote
Loading...
Searching...
No Matches

◆ reindex()

template<concepts::projection_map auto Projections, concepts::product_type T>
auto kumi::reindex ( T && t)
inlinenodiscardconstexpr

Reindex elements of a kumi::product_type.

This will issue a compile time error if any Idx is outside [0, size_v<T>[.

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 index to be lesser or greater than t size or the fact they can appear multiple times.
Template Parameters
ProjectionsA kumi::projection_map representing the reindexed slot of the elements
Parameters
tkumi::product_type to reindex
Returns
A potentially nested tuple following the Indexes order

Helper type

namespace kumi::result
{
template<product_type T, index_map auto Idxs> struct reindex;
template<product_type T, index_map auto Idxs>
using reindex_t= typename reindex<T,Idxs>::type;
}
constexpr auto reindex(T &&t)
Reindex elements of a kumi::product_type.
Definition reorder.hpp:137

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";
}
KUMI_CUDA projection_map(Ts...) -> projection_map< Ts... >
kumi::indexes_t deduction guide
consteval auto indexes(Ts... ts) noexcept
Creates a kumi::projection_map object, deducing the target type from the types of arguments.
Definition projections.hpp:127
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