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

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

template<typename T , typename U >
constexpr auto ghassanpl::push_back_unique (std::vector< T > &vector, U &&value)
 
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< Vghassanpl::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::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 >
decltype(autoghassanpl::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 
)

Same as map_find()

See also
map_find()

Definition at line 165 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 
)

Same as map_find()

See also
map_find()

Definition at line 160 of file containers.h.

◆ erase_at_swap()

template<typename T >
constexpr 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 96 of file containers.h.

◆ erase_single() [1/2]

template<typename K , typename V , typename COMP , typename U >
constexpr 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 46 of file containers.h.

◆ erase_single() [2/2]

template<typename T , typename U >
constexpr 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 34 of file containers.h.

◆ erase_single_if()

template<typename T , typename PRED >
constexpr 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 58 of file containers.h.

◆ erase_single_swap()

template<typename T , typename U >
constexpr 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 70 of file containers.h.

◆ erase_single_swap_if()

template<typename T , typename PRED >
constexpr 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 83 of file containers.h.

◆ map_at()

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

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

Definition at line 126 of file containers.h.

◆ map_at_or_default()

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.

Definition at line 116 of file containers.h.

◆ map_find()

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.

Definition at line 108 of file containers.h.

◆ map_find_value()

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.

Definition at line 146 of file containers.h.

◆ push_back_unique()

template<typename T , typename U >
constexpr 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 21 of file containers.h.