Wildmeshing Toolkit
Loading...
Searching...
No Matches
DynamicArray.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <vector>
5
6namespace wmtk::utils {
7
8
9template <typename T, uint64_t ArraySize = 50>
11{
12public:
14 {
15 public:
16 Iterator(const DynamicArray* container, const uint64_t index = 0);
18 bool operator!=(const Iterator& other) const;
19 T operator*();
20
21 private:
23 uint64_t m_index = 0;
24 };
25
26
27 T& operator[](const uint64_t index);
28 const T& operator[](const uint64_t index) const;
29
30 void emplace_back(const T& val);
31
32 uint64_t size() const;
33 uint64_t capacity() const;
34
40 constexpr static uint64_t array_size();
41
42 void reserve(const uint64_t new_capacity);
43
44 bool uses_vector() const;
45
46 Iterator begin() const { return Iterator(this); }
47 Iterator end() const { return Iterator(this, m_end_index); }
48
49private:
50 void switch_to_vector();
51
52private:
53 std::array<T, ArraySize> m_array;
54 std::vector<T> m_vector;
55
56 bool m_use_vector = false;
57 uint64_t m_end_index = 0;
58};
59
60} // namespace wmtk::utils
61
62#include "DynamicArray.hxx"
bool operator!=(const Iterator &other) const
void reserve(const uint64_t new_capacity)
void emplace_back(const T &val)
T & operator[](const uint64_t index)
std::vector< T > m_vector
std::array< T, ArraySize > m_array
static constexpr uint64_t array_size()
Return the size of the static array.
uint64_t capacity() const