CPP-TOOLBOX
Loading...
Searching...
No Matches
collection_utils Namespace Reference

Functions

template<typename T>
std::vector< Tjoin_vectors (const std::vector< T > &v1, const std::vector< T > &v2)
 Concatenate two vectors into a single vector.
 
template<typename T, typename Func>
void for_each_in_vector (std::vector< T > &vec, Func func)
 Apply a function to each element of a modifiable vector.
 
template<typename Container>
bool any_of (const Container &c)
 Check if any element in the container evaluates to true.
 
template<typename Container>
bool all_of (const Container &c)
 Check if all elements in the container evaluate to true.
 
template<typename T, typename Func>
void for_each_in_vector (const std::vector< T > &vec, Func func)
 Apply a function to each element of a read-only vector.
 
template<typename T>
std::vector< Tjoin_all_vectors (const std::vector< std::vector< T > > &vectors)
 Concatenate a list of vectors into a single vector.
 
template<typename T, typename Func>
auto map_vector (const std::vector< T > &vec, Func func)
 Transform a vector by applying a function to each element.
 

Function Documentation

◆ all_of()

template<typename Container>
bool collection_utils::all_of ( const Container & c)

Check if all elements in the container evaluate to true.

Elements are cast to bool before evaluation.

Template Parameters
ContainerType of container supporting begin() and end().
Parameters
cContainer to check.
Returns
true if all elements are truthy, false otherwise.

◆ any_of()

template<typename Container>
bool collection_utils::any_of ( const Container & c)

Check if any element in the container evaluates to true.

Elements are cast to bool before evaluation.

Template Parameters
ContainerType of container supporting begin() and end().
Parameters
cContainer to check.
Returns
true if at least one element is truthy, false otherwise.

◆ for_each_in_vector() [1/2]

template<typename T, typename Func>
void collection_utils::for_each_in_vector ( const std::vector< T > & vec,
Func func )

Apply a function to each element of a read-only vector.

Template Parameters
TType of elements in the vector.
FuncType of the function to apply. Must be callable with const T&.
Parameters
vecVector whose elements will be processed.
funcFunction to apply to each element.

◆ for_each_in_vector() [2/2]

template<typename T, typename Func>
void collection_utils::for_each_in_vector ( std::vector< T > & vec,
Func func )

Apply a function to each element of a modifiable vector.

Template Parameters
TType of elements in the vector.
FuncType of the function to apply. Must be callable with T&.
Parameters
vecVector whose elements will be processed.
funcFunction to apply to each element.

◆ join_all_vectors()

template<typename T>
std::vector< T > collection_utils::join_all_vectors ( const std::vector< std::vector< T > > & vectors)

Concatenate a list of vectors into a single vector.

Template Parameters
TType of elements in the vectors.
Parameters
vectorsA vector of vectors to join.
Returns
A new vector containing all elements from all input vectors in order.

◆ join_vectors()

template<typename T>
std::vector< T > collection_utils::join_vectors ( const std::vector< T > & v1,
const std::vector< T > & v2 )

Concatenate two vectors into a single vector.

Template Parameters
TType of elements in the vectors.
Parameters
v1First vector.
v2Second vector.
Returns
A new vector containing all elements from v1 followed by all elements from v2.

◆ map_vector()

template<typename T, typename Func>
auto collection_utils::map_vector ( const std::vector< T > & vec,
Func func )

Transform a vector by applying a function to each element.

Template Parameters
TType of input elements.
FuncType of the function to apply. Must be callable with const T&.
Parameters
vecInput vector.
funcFunction to apply to each element.
Returns
A new vector where each element is the result of applying func to the corresponding input element.