header_utils
Loading...
Searching...
No Matches
Containers

Functions that operate on containers like maps and vectors. More...

Functions

template<typename T, typename U>
constexpr auto ghassanpl::push_back_unique (std::vector< T > &vector, U &&value)
 Pushes a value to a vector if it doesn't already exists.
template<typename T, typename U>
constexpr std::optional< T > ghassanpl::erase_single (std::vector< T > &vector, U &&value)
 Finds a value in the vector, and erases it, but returns the value.
template<typename K, typename V, typename COMP, typename U>
constexpr std::optional< V > ghassanpl::erase_single (std::map< K, V, COMP > &map, U &&key)
 Finds a value in the map, and erases it, but returns the value.
template<typename T, typename PRED>
constexpr std::optional< T > ghassanpl::erase_single_if (std::vector< T > &vector, PRED &&pred)
 Finds a value in the vector by predicate, and erases it.
template<typename T, typename U>
constexpr std::optional< T > ghassanpl::erase_single_swap (std::vector< T > &vector, U &&value)
 Finds and erases a value in vector, not preserving item order (swapping last item to erased).
template<typename T, typename PRED>
constexpr std::vector< T > ghassanpl::erase_swap_if (std::vector< T > &vector, PRED &&pred)
 Finds and erases a value in vector, not preserving item order (swapping last item to erased).
template<typename T, typename PRED>
constexpr std::optional< T > ghassanpl::erase_single_swap_if (std::vector< T > &vector, PRED &&pred)
 Finds and erases a value in vector by predicate, not preserving item order (swapping last item to erased).
template<typename T>
constexpr std::optional< T > ghassanpl::erase_at_swap (std::vector< T > &vector, size_t index)
 Erases the element at index in vector, not preserving item order (swapping last item to erased).
template<typename KEY, typename MAP>
auto ghassanpl::map_find (MAP &map, KEY &&key)
 Finds the value associated with key in the map and retuns a pointer to it, or nullptr if none found.
template<typename DEF, typename KEY, typename MAP>
auto ghassanpl::map_at_or_default (MAP &&map, KEY &&key, DEF &&def)
 Finds the value associated with key in the map and retuns it, or def if none found.
template<typename KEY, typename MAP>
auto ghassanpl::map_at_or_default (MAP &&map, KEY &&key)
 Finds the value associated with key in the map and retuns it, or def if none found.
template<typename KEY, typename MAP>
decltype(auto) ghassanpl::map_at (MAP &&map, KEY &&key)
 Basically map.at() but works with heterogenous key types.
template<typename MAP, typename VAL>
auto ghassanpl::map_find_value (MAP &map, VAL const *value)
 Finds the first value of a map element, and returns a pointer to its key, or nullptr if none found.
template<typename K, typename V, typename C, typename VAL>
auto ghassanpl::at_ptr (std::map< K, V, C > const &map, VAL &&value)
 Same as map_find().
template<typename K, typename V, typename C, typename VAL>
auto ghassanpl::at_ptr (std::map< K, V, C > &map, VAL &&value)
 Same as map_find().

Detailed Description

Functions that operate on containers like maps and vectors.

Function Documentation

◆ at_ptr() [1/2]

template<typename K, typename V, typename C, typename VAL>
auto ghassanpl::at_ptr ( std::map< K, V, C > & map,
VAL && value )
nodiscard

Same as map_find().

See also
map_find()

Definition at line 196 of file containers.h.

◆ at_ptr() [2/2]

template<typename K, typename V, typename C, typename VAL>
auto ghassanpl::at_ptr ( std::map< K, V, C > const & map,
VAL && value )
nodiscard

Same as map_find().

See also
map_find()

Definition at line 191 of file containers.h.

◆ erase_at_swap()

template<typename T>
std::optional< T > ghassanpl::erase_at_swap ( std::vector< T > & vector,
size_t index )
constexpr

Erases the element at index in vector, not preserving item order (swapping last item to erased).

Definition at line 117 of file containers.h.

◆ erase_single() [1/2]

template<typename K, typename V, typename COMP, typename U>
std::optional< V > ghassanpl::erase_single ( std::map< K, V, COMP > & map,
U && key )
constexpr

Finds a value in the map, and erases it, but returns the value.

Definition at line 47 of file containers.h.

◆ erase_single() [2/2]

template<typename T, typename U>
std::optional< T > ghassanpl::erase_single ( std::vector< T > & vector,
U && value )
constexpr

Finds a value in the vector, and erases it, but returns the value.

Definition at line 35 of file containers.h.

◆ erase_single_if()

template<typename T, typename PRED>
std::optional< T > ghassanpl::erase_single_if ( std::vector< T > & vector,
PRED && pred )
constexpr

Finds a value in the vector by predicate, and erases it.

Definition at line 59 of file containers.h.

◆ erase_single_swap()

template<typename T, typename U>
std::optional< T > ghassanpl::erase_single_swap ( std::vector< T > & vector,
U && value )
constexpr

Finds and erases a value in vector, not preserving item order (swapping last item to erased).

Definition at line 71 of file containers.h.

◆ erase_single_swap_if()

template<typename T, typename PRED>
std::optional< T > ghassanpl::erase_single_swap_if ( std::vector< T > & vector,
PRED && pred )
constexpr

Finds and erases a value in vector by predicate, not preserving item order (swapping last item to erased).

Definition at line 104 of file containers.h.

◆ erase_swap_if()

template<typename T, typename PRED>
std::vector< T > ghassanpl::erase_swap_if ( std::vector< T > & vector,
PRED && pred )
constexpr

Finds and erases a value in vector, not preserving item order (swapping last item to erased).

Definition at line 85 of file containers.h.

◆ map_at()

template<typename KEY, typename MAP>
decltype(auto) ghassanpl::map_at ( MAP && map,
KEY && key )
nodiscard

Basically map.at() but works with heterogenous key types.

Definition at line 157 of file containers.h.

◆ map_at_or_default() [1/2]

template<typename KEY, typename MAP>
auto ghassanpl::map_at_or_default ( MAP && map,
KEY && key )
nodiscard

Finds the value associated with key in the map and retuns it, or def if none found.

Definition at line 147 of file containers.h.

◆ map_at_or_default() [2/2]

template<typename DEF, typename KEY, typename MAP>
auto ghassanpl::map_at_or_default ( MAP && map,
KEY && key,
DEF && def )
nodiscard

Finds the value associated with key in the map and retuns it, or def if none found.

Definition at line 137 of file containers.h.

◆ map_find()

template<typename KEY, typename MAP>
auto ghassanpl::map_find ( MAP & map,
KEY && key )
nodiscard

Finds the value associated with key in the map and retuns a pointer to it, or nullptr if none found.

Definition at line 129 of file containers.h.

◆ map_find_value()

template<typename MAP, typename VAL>
auto ghassanpl::map_find_value ( MAP & map,
VAL const * value )
nodiscard

Finds the first value of a map element, and returns a pointer to its key, or nullptr if none found.

Definition at line 177 of file containers.h.

◆ push_back_unique()

template<typename T, typename U>
auto ghassanpl::push_back_unique ( std::vector< T > & vector,
U && value )
constexpr

Pushes a value to a vector if it doesn't already exists.

Definition at line 22 of file containers.h.