Templa 0.0.1-alpha
C++ Metaprogramming Utilities
Loading...
Searching...
No Matches
algorithms.hpp File Reference

Algorithms. More...

#include <array>
#include <iostream>
#include <vector>
#include <set>
#include "concepts.hpp"
#include "pack.hpp"
#include <algorithm>
#include "static_for.hpp"

Go to the source code of this file.

Classes

struct  templa::algorithms::min< Es >
 Computes the minimum value among a pack of compile-time constants. More...
struct  templa::algorithms::min_from< e >
 Computes the minimum value from a container-like object at compile time. More...
struct  templa::algorithms::max< Es >
 Computes the maximum value among a pack of compile-time constants. More...
struct  templa::algorithms::max_from< e >
 Computes the maximum value from a container-like object at compile time. More...
struct  templa::algorithms::unique< Es >
 Computes a compile-time unique sequence from a pack of values. More...
struct  templa::algorithms::unique_from< a >
 Computes a compile-time unique sequence from a container expression. More...
struct  templa::algorithms::reverse< elems >
 Reverses a compile-time pack of constant values. More...
struct  templa::algorithms::reverse_from< a >
 Reverses the elements of a constexpr container at compile time. More...
struct  templa::algorithms::join< Strs >
 Compile-time string concatenation of multiple std::string_view references. More...

Functions

template<typename T, typename... Formats, std::size_t N, std::size_t... Is>
std::tuple< Formats... > templa::algorithms::as_tuple (std::array< T, N > const &arr, std::index_sequence< Is... >)
 Converts a fixed-size array into a tuple using specified format types.
template<typename T, typename... Formats, std::size_t N>
std::tuple< Formats... > templa::algorithms::as_tuple (std::array< T, N > const &arr)
 Forwards array along with index sequence of the array size to the implementation.
template<typename T, std::size_t N, std::size_t M, std::size_t... I, std::size_t... J>
constexpr auto templa::algorithms::internal::concat_impl (std::array< T, N > const &lhs, std::array< T, M > const &rhs, std::index_sequence< I... >, std::index_sequence< J... >)
template<typename T, typename O>
void templa::algorithms::flatten (const std::vector< T > &in, std::vector< O > &out)
 Flattens a single-level std::vector<T> into another vector.
template<typename T, typename O>
void templa::algorithms::flatten (const std::vector< std::vector< T > > &in, std::vector< O > &out)
 Flattens a two-level nested std::vector<std::vector<T>> into another vector.

Detailed Description

Algorithms.

Function Documentation

◆ as_tuple() [1/2]

template<typename T, typename... Formats, std::size_t N>
std::tuple< Formats... > templa::algorithms::as_tuple ( std::array< T, N > const & arr)

Forwards array along with index sequence of the array size to the implementation.

Template Parameters
TThe element type of the input std::array.
FormatsA parameter pack representing the target types for each tuple element.
NThe size of the input array.
Parameters
arrThe input std::array of type T with N elements.

◆ as_tuple() [2/2]

template<typename T, typename... Formats, std::size_t N, std::size_t... Is>
std::tuple< Formats... > templa::algorithms::as_tuple ( std::array< T, N > const & arr,
std::index_sequence< Is... >  )

Converts a fixed-size array into a tuple using specified format types.

Template Parameters
TThe element type of the input std::array.
FormatsA parameter pack representing the target types for each tuple element.
NThe size of the input array.
IsA parameter pack of indices used to access elements in the array.
Parameters
arrThe input std::array of type T with N elements.
std::index_sequence<Is...>used to unpack array indices at compile time.
Returns
std::tuple<Formats...> A tuple containing elements of the array converted to the specified format types.
Note
The number of elements in Formats... must match the number of indices in Is....

◆ flatten() [1/2]

template<typename T, typename O>
void templa::algorithms::flatten ( const std::vector< std::vector< T > > & in,
std::vector< O > & out )

Flattens a two-level nested std::vector<std::vector<T>> into another vector.

Recursively flattens each inner vector into the output vector.

Template Parameters
TThe element type of the innermost vectors.
OThe element type of the output vector.
Parameters
inThe nested input vector to flatten.
outThe output vector to append to.

◆ flatten() [2/2]

template<typename T, typename O>
void templa::algorithms::flatten ( const std::vector< T > & in,
std::vector< O > & out )

Flattens a single-level std::vector<T> into another vector.

Copies elements from the input vector to the output vector using insert.

Template Parameters
TThe element type of the input vector.
OThe element type of the output vector.
Parameters
inThe input vector to flatten.
outThe output vector to append to.