rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
static_vector.h
Go to the documentation of this file.
1#pragma once
2
3template <typename T, int TSlots>
5
6 void clear() {
7 m_size = 0;
8 }
9
10 template <typename TSearch>
11 T* find(const TSearch& search) const {
12 for (size_t i = 0; i < m_size; i++) {
13 if (m_storage[i] == search) {
14 return const_cast<T*>(&m_storage[i]);
15 }
16 }
17
18 return nullptr;
19 }
20
21 T* add(const T& value) {
22 if (m_size >= TSlots) {
23 // vector full, discard
24 return nullptr;
25 }
26
27 T& location = m_storage[m_size];
28
29 location = value;
30 m_size++;
31
32 return &location;
33 }
34
35 T& get(size_t i) {
36 return m_storage[i];
37 }
38
39 size_t getCount() const {
40 return m_size;
41 }
42
43private:
44 T m_storage[TSlots];
45 // wow: order of field declaration matters here, gcc glitch?
46 size_t m_size = 0;
47};
T & get(size_t i)
T * add(const T &value)
T * find(const TSearch &search) const
size_t getCount() const
T m_storage[TSlots]