4#include <foundation/DataTypes.h>
5#include <foundation/Macro.h>
20template<auto Nullable>
28 template<
typename K,
typename V>
29 FORCE_INLINE
static void RemoveByKey(std::vector<std::pair<K, V>> &vector,
const K &key)
31 std::erase_if(vector, [&key](
const std::pair<K, V> &pair) {
return pair.first == key; });
38 template<
typename K,
typename V>
39 FORCE_INLINE
static typename std::vector<std::pair<K, V>>::iterator
42 return std::find_if(vector.begin(), vector.end(),
43 [&key](
const std::pair<K, V> &pair) { return pair.first == key; });
50 template<
typename K,
typename V>
51 FORCE_INLINE
static V
GetByKey(std::vector<std::pair<K, V>> &vector,
const K &key)
55 if (iterator == vector.end())
58 return iterator->second;
65 template<
typename K,
typename V>
66 FORCE_INLINE
static bool MoveToLastIndex(std::vector<std::pair<K, V>> &vector,
const K &key)
70 if (iterator == vector.end())
74 std::pair<K, V> element = *iterator;
75 vector.erase(iterator);
76 vector.push_back(element);
93 FORCE_INLINE
static int32
IndexOf(
const std::vector<T> &vector,
const T &element)
95 auto iterator = std::find(vector.begin(), vector.end(), element);
96 if (iterator == vector.end())
99 return static_cast<int32
>(iterator - vector.begin());
106 template<Integral R =
int64,
typename T>
107 FORCE_INLINE
static R
Size(
const std::vector<T> &vector)
109 return static_cast<R
>(vector.size());
117 FORCE_INLINE
static bool Remove(std::vector<T> &vector,
const T &element)
119 auto indexOf =
IndexOf(vector, element);
123 vector.erase(vector.begin() + indexOf);
132 FORCE_INLINE
static bool Contains(
const std::vector<T> &cards,
const T &element)
134 return std::ranges::find(cards, element) != std::ranges::end(cards);
A utility which contains essential operation functions for list of pairs.
Definition Collections.h:22
static FORCE_INLINE bool MoveToLastIndex(std::vector< std::pair< K, V > > &vector, const K &key)
Finds and moves entry to the top of a list for given key.
Definition Collections.h:66
static FORCE_INLINE void RemoveByKey(std::vector< std::pair< K, V > > &vector, const K &key)
Finds and deletes entry for given key.
Definition Collections.h:29
static FORCE_INLINE std::vector< std::pair< K, V > >::iterator GetIteratorByKey(std::vector< std::pair< K, V > > &vector, const K &key)
Finds and returns entry's iterator for given key.
Definition Collections.h:40
static FORCE_INLINE V GetByKey(std::vector< std::pair< K, V > > &vector, const K &key)
Finds and returns entry's value for given key.
Definition Collections.h:51
A utility which contains essential operation functions for list.
Definition Collections.h:86
static FORCE_INLINE bool Remove(std::vector< T > &vector, const T &element)
Finds and deletes given value.
Definition Collections.h:117
static FORCE_INLINE int32 IndexOf(const std::vector< T > &vector, const T &element)
Finds and returns index of given value.
Definition Collections.h:93
static FORCE_INLINE R Size(const std::vector< T > &vector)
Returns size of given list.
Definition Collections.h:107
static FORCE_INLINE bool Contains(const std::vector< T > &cards, const T &element)
Checks whether given value is present in a list.
Definition Collections.h:132
Checks whether T is integral.
Definition Collections.h:14