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

Computes a compile-time unique sequence from a pack of values. More...

#include <algorithms.hpp>

Inheritance diagram for templa::algorithms::unique< Es >:
templa::internal::uniform_element_identity< Es... >

Public Types

using identity_type = typename templa::internal::uniform_element_identity<Es...>
 Type containing the uniform array of input values.
using old_array_type = typename identity_type::uniform_type
 The type of the original uniform array.
Public Types inherited from templa::internal::uniform_element_identity< Es... >
using uniform_type
 Type alias for the uniform std::array of elements.
using value_type
 Value type of the uniform_type.

Static Public Attributes

static constexpr auto unique_sequence
 The resulting array with unique elements from the input pack.
Static Public Attributes inherited from templa::internal::uniform_element_identity< Es... >
static constexpr std::size_t size
 Number of elements.
static constexpr bool valid
 Check if all elements have the same decayed type and are comparable.
static constexpr uniform_type identity_value
 Static array holding the elements.

Detailed Description

template<auto... Es>
struct templa::algorithms::unique< Es >

Computes a compile-time unique sequence from a pack of values.

Inherits from templa::internal::uniform_element_identity to obtain a uniform array representation of the input pack and eliminates duplicates in the order they appear.

Template Parameters
EsA parameter pack of compile-time constant values.

Member Data Documentation

◆ unique_sequence

template<auto... Es>
auto templa::algorithms::unique< Es >::unique_sequence
staticconstexpr
Initial value:
= []() consteval
{
constexpr std::size_t n_unique = internal::count_unique(identity_type::identity_value);
std::array<typename identity_type::value_type, n_unique> new_arr{};
std::size_t idx = 0;
constexpr auto lam = []<std::size_t... I>(
std::array<typename identity_type::value_type, n_unique> &n,
std::size_t &idx)
{
constexpr auto &old = identity_type::identity_value;
((!internal::exists_until(old, old[I], I) ? (n[idx++] = old[I], void()) : void()), ...);
};
static_for<identity_type::size>(lam, new_arr, idx);
return new_arr;
}()

The resulting array with unique elements from the input pack.

The algorithm preserves the order of first occurrences and excludes duplicates using exists_until from the internal utilities.


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