5#ifndef WPIUTIL_WPI_UIDVECTOR_H_
6#define WPIUTIL_WPI_UIDVECTOR_H_
27 while (m_it != m_end && !*m_it) {
39 }
while (m_it != m_end && !*m_it);
50 return m_it == oth.m_it;
54 return m_it != oth.m_it;
72template <typename T, typename std::vector<T>::size_type reuse_threshold>
80 using size_type =
typename std::vector<T>::size_type;
86 bool empty() const noexcept {
return m_active_count == 0; }
94 template <
class... Args>
97 if (m_free.size() < reuse_threshold) {
98 uid = m_vector.size();
99 m_vector.emplace_back(std::forward<Args>(args)...);
101 uid = m_free.front();
102 m_free.erase(m_free.begin());
103 m_vector[uid] = T(std::forward<Args>(args)...);
114 if (uid >= m_vector.size() || !m_vector[uid]) {
117 m_free.push_back(uid);
118 auto rv = std::move(m_vector[uid]);
135 return iterator(m_vector.begin(), m_vector.end());
152 std::vector<T> m_vector;
153 std::vector<size_type> m_free;
Vector which provides an integrated freelist for removal and reuse of individual elements.
Definition: UidVector.h:73
void clear() noexcept
Removes all elements.
Definition: UidVector.h:127
const_iterator cbegin() const noexcept
Definition: UidVector.h:140
const T & operator[](size_type i) const
Definition: UidVector.h:89
T * pointer
Definition: UidVector.h:76
iterator begin() noexcept
Definition: UidVector.h:134
T value_type
Definition: UidVector.h:75
T & reference
Definition: UidVector.h:78
typename std::vector< T >::size_type size_type
Definition: UidVector.h:80
bool empty() const noexcept
Definition: UidVector.h:86
const T * const_pointer
Definition: UidVector.h:77
T & operator[](size_type i)
Definition: UidVector.h:88
impl::UidVectorIterator< typename std::vector< T >::const_iterator > const_iterator
Definition: UidVector.h:84
const_iterator end() const noexcept
Definition: UidVector.h:144
size_type emplace_back(Args &&... args)
Definition: UidVector.h:95
const T & const_reference
Definition: UidVector.h:79
typename std::vector< T >::difference_type difference_type
Definition: UidVector.h:81
const_iterator begin() const noexcept
Definition: UidVector.h:137
const_iterator cend() const noexcept
Definition: UidVector.h:147
T erase(size_type uid)
Removes the identified element by replacing it with a default-constructed one.
Definition: UidVector.h:113
size_type size() const noexcept
Definition: UidVector.h:87
impl::UidVectorIterator< typename std::vector< T >::iterator > iterator
Definition: UidVector.h:82
iterator end() noexcept
Definition: UidVector.h:143
Definition: UidVector.h:16
reference operator*() const noexcept
Definition: UidVector.h:32
UidVectorIterator & operator++() noexcept
Definition: UidVector.h:35
typename It::reference reference
Definition: UidVector.h:21
UidVectorIterator(It it, It end)
Definition: UidVector.h:25
typename It::difference_type difference_type
Definition: UidVector.h:20
bool operator==(const UidVectorIterator &oth) const noexcept
Definition: UidVector.h:49
typename It::pointer pointer
Definition: UidVector.h:22
bool operator!=(const UidVectorIterator &oth) const noexcept
Definition: UidVector.h:53
UidVectorIterator operator++(int) noexcept
Definition: UidVector.h:43
pointer operator->() const noexcept
Definition: UidVector.h:33
UidVectorIterator()=default
std::forward_iterator_tag iterator_type
Definition: UidVector.h:18
typename It::value_type value_type
Definition: UidVector.h:19
Definition: ntcore_cpp.h:26