Templa 0.0.1-alpha
C++ Metaprogramming Utilities
Loading...
Searching...
No Matches
templa::algorithms::unique_from< a > Struct Template Reference

Computes a compile-time unique sequence from a container expression. More...

#include <algorithms.hpp>

Static Public Attributes

static constexpr auto unique_sequence
 The resulting array with unique elements from the input container.

Detailed Description

template<auto a>
requires (concepts::Container<std::remove_cv_t<decltype(a)>>) && (concepts::Comparable<std::remove_cv_t<decltype(a)>>)
struct templa::algorithms::unique_from< a >

Computes a compile-time unique sequence from a container expression.

Accepts a constexpr container and eliminates duplicate elements using the same logic as the unique struct. The container must be both a Container and Comparable.

Template Parameters
aA container expression (e.g., std::array) with known contents. @requires The container must satisfy concepts::Container and concepts::Comparable.

Member Data Documentation

◆ unique_sequence

template<auto a>
auto templa::algorithms::unique_from< a >::unique_sequence
staticconstexpr
Initial value:
= []() consteval
{
std::array<typename forwarded_type::type, internal::count_unique(old)> new_arr{};
std::size_t idx = 0;
constexpr auto lam = []<std::size_t... I>(
const old_array_type &o,
std::array<typename forwarded_type::type, internal::count_unique(old)> &n,
std::size_t &idx)
{
((!internal::exists_until(old, old[I], I) ? (n[idx++] = old[I], void()) : void()), ...);
};
static_for<old.size()>(lam, old, new_arr, idx);
return new_arr;
}()
decltype(a)::value_type type
Value type of the container.
Definition pack.hpp:97

The resulting array with unique elements from the input container.

Uses an index-based iteration with compile-time filtering to populate a new array containing only the first occurrences of each element.


The documentation for this struct was generated from the following file: