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

◆ reorder()

template<std::size_t... Idx, concepts::product_type T>
auto kumi::reorder ( T && t)
inlinenodiscardconstexpr

Reorder elements of a product type.

This function 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.
reorder(tuple) works and is equivalent to reorder<>(tuple)
Template Parameters
IdxReordered index of elements
Parameters
tThe product type to reorder
Returns
A product type with the type of t with elements equal to get<Idx>(t).

Helper type

namespace kumi::result
{
template<product_type T,std::size_t... Idx> struct reorder;
template<product_type T,std::size_t... Idx>
using reorder_t = typename reorder<T,Idx...>::type;
}
constexpr auto reorder(T &&t)
Reorder elements of a product type.
Definition reorder.hpp:51

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

Examples:

Tuple:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
auto values = kumi::tuple { 1, 'a', 0.1 };
std::cout << values << "\n";
std::cout << kumi::reorder<2,1,0>(values) << "\n";
std::cout << kumi::reorder<2,1,0,1,2>(values) << "\n";
std::cout << kumi::reorder<1,1>(values) << "\n";
}
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 };
std::cout << values << "\n";
std::cout << kumi::reorder<2,1,0>(values) << "\n";
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36