6#ifndef EGT_FIXEDVECTOR_H
7#define EGT_FIXEDVECTOR_H
17#include <egt/detail/meta.h>
18#include <initializer_list>
30template <
class BinaryPredicate,
class InputIterator1,
class InputIterator2>
31constexpr bool cmp(InputIterator1 first1, InputIterator1 last1,
32 InputIterator2 first2, InputIterator2 last2,
35 for (; first1 != last1 && first2 != last2; ++first1, ++first2)
37 if (!pred(*first1, *first2))
42 return first1 == last1 && first2 == last2;
45template <
typename InputIt,
typename OutputIt>
46constexpr OutputIt
move(InputIt b, InputIt e, OutputIt to)
48 for (; b != e; ++b, (void)++to)
64template <
typename T, std::
size_t Capacity = 5>
107 return m_data.begin();
112 return m_data.begin();
117 return m_data.begin() +
size();
122 return m_data.begin() +
size();
165 constexpr auto capacity() const noexcept {
return Capacity; }
166 constexpr auto size() const noexcept {
return m_size; }
167 constexpr auto empty() const noexcept {
return m_size == 0; }
168 constexpr void clear() noexcept { m_size = 0; }
170 constexpr const T*
data()
const
172 return m_data.data();
188 throw std::out_of_range(
"FixedVector::at");
196 throw std::out_of_range(
"FixedVector::at");
215 return m_data[
size() - 1];
220 return m_data[
size() - 1];
223 template <
typename U>
226 assert(!full() &&
"FixedVector is full!");
233 assert(!full() &&
"FixedVector is full!");
237 template <
typename... Args>
240 assert(!full() &&
"tried to emplace_back on full storage");
241 new (
end()) T(std::forward<Args>(args)...);
248 other = std::move(*
this);
249 (*this) = std::move(tmp);
254 return erase(position, position + 1);
272 constexpr bool full()
const
277 template <
typename InputIt>
278 void destroy(InputIt first, InputIt last)
noexcept
280 assert(first >=
data() && first <=
end()
281 &&
"first is out-of-bounds");
282 assert(last >=
data() && last <=
end()
283 &&
"last is out-of-bounds");
284 for (; first != last; ++first)
290 using Storage = std::array<T, Capacity>;
293 std::size_t m_size{0};
296template <
typename T,
size_t Capacity>
300 return a.size() == b.size()
301 and
detail::cmp(a.begin(), a.end(), b.begin(), b.end(),
305template <
typename T,
size_t Capacity>
309 return detail::cmp(a.begin(), a.end(), b.begin(), b.end(),
313template <
typename T,
size_t Capacity>
320template <
typename T,
size_t Capacity>
324 return detail::cmp(a.begin(), a.end(), b.begin(), b.end(),
325 std::less_equal<> {});
328template <
typename T,
size_t Capacity>
332 return detail::cmp(a.begin(), a.end(), b.begin(), b.end(),
336template <
typename T,
size_t Capacity>
340 return detail::cmp(a.begin(), a.end(), b.begin(), b.end(),
341 std::greater_equal<> {});
constexpr vector that tries to behave like, or have an API like, std::vector.
Definition fixedvector.h:66
constexpr auto capacity() const noexcept
Definition fixedvector.h:165
constexpr const_iterator begin() const noexcept
Definition fixedvector.h:110
constexpr const_reference front() const noexcept
Definition fixedvector.h:206
void emplace_back(Args &&... args) noexcept
Definition fixedvector.h:238
constexpr FixedVector(std::initializer_list< T > init) noexcept
Definition fixedvector.h:99
constexpr reference at(size_type pos)
Definition fixedvector.h:185
constexpr const_iterator end() const noexcept
Definition fixedvector.h:120
constexpr FixedVector(I begin, const I &end) noexcept
Definition fixedvector.h:81
constexpr FixedVector()=default
constexpr void push_back(U &&value) noexcept
Definition fixedvector.h:224
constexpr const T * data() const
Definition fixedvector.h:170
value_type const & const_reference
Definition fixedvector.h:71
T * iterator
Definition fixedvector.h:74
constexpr auto size() const noexcept
Definition fixedvector.h:166
constexpr reference operator[](size_type pos) noexcept
Definition fixedvector.h:175
T const * const_iterator
Definition fixedvector.h:75
::std::reverse_iterator< const_iterator > const_reverse_iterator
Definition fixedvector.h:78
value_type & reference
Definition fixedvector.h:70
size_t size_type
Definition fixedvector.h:76
constexpr const_iterator cbegin() const noexcept
Definition fixedvector.h:150
constexpr FixedVector(size_type count, const T &value) noexcept
Definition fixedvector.h:90
constexpr reference back() noexcept
Definition fixedvector.h:212
constexpr iterator begin() noexcept
Definition fixedvector.h:105
constexpr void clear() noexcept
Definition fixedvector.h:168
constexpr const_iterator cend() const noexcept
Definition fixedvector.h:160
constexpr reference front() noexcept
Definition fixedvector.h:201
constexpr iterator erase(const_iterator first, const_iterator last) noexcept
Definition fixedvector.h:257
constexpr const_reference back() const noexcept
Definition fixedvector.h:217
constexpr const_iterator cend() noexcept
Definition fixedvector.h:155
constexpr iterator end() noexcept
Definition fixedvector.h:115
T * pointer
Definition fixedvector.h:72
constexpr const_reference operator[](size_type pos) const noexcept
Definition fixedvector.h:180
constexpr auto empty() const noexcept
Definition fixedvector.h:167
const_reverse_iterator rend() const noexcept
Definition fixedvector.h:140
reverse_iterator rbegin() noexcept
Definition fixedvector.h:125
std::ptrdiff_t difference_type
Definition fixedvector.h:69
reverse_iterator rend() noexcept
Definition fixedvector.h:135
::std::reverse_iterator< iterator > reverse_iterator
Definition fixedvector.h:77
T const * const_pointer
Definition fixedvector.h:73
constexpr iterator erase(const_iterator position) noexcept
Definition fixedvector.h:252
constexpr void swap(FixedVector &other) noexcept
Definition fixedvector.h:245
constexpr const_iterator cbegin() noexcept
Definition fixedvector.h:145
T value_type
Definition fixedvector.h:68
constexpr const_reference at(size_type pos) const
Definition fixedvector.h:193
void push_back() noexcept
Appends a default constructed T at the end of the FixedVector.
Definition fixedvector.h:231
const_reverse_iterator rbegin() const noexcept
Definition fixedvector.h:130
constexpr bool cmp(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred)
Definition fixedvector.h:31
constexpr OutputIt move(InputIt b, InputIt e, OutputIt to)
Definition fixedvector.h:46
constexpr bool operator!=(const Color &lhs, const Color &rhs)
Color operator.
Definition color.h:509
constexpr bool operator>(FixedVector< T, Capacity > const &a, FixedVector< T, Capacity > const &b) noexcept
Definition fixedvector.h:329
constexpr bool operator==(const Color &lhs, const Color &rhs)
Color operator.
Definition color.h:500
constexpr bool operator<=(FixedVector< T, Capacity > const &a, FixedVector< T, Capacity > const &b) noexcept
Definition fixedvector.h:321
constexpr bool operator<(FixedVector< T, Capacity > const &a, FixedVector< T, Capacity > const &b) noexcept
Definition fixedvector.h:306
constexpr bool operator>=(FixedVector< T, Capacity > const &a, FixedVector< T, Capacity > const &b) noexcept
Definition fixedvector.h:337
EGT framework namespace.
Definition animation.h:24