rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
util
containers
static_vector.h
Go to the documentation of this file.
1
#pragma once
2
3
template
<
typename
T,
int
TSlots>
4
struct
static_vector
{
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
43
private
:
44
T
m_storage
[TSlots];
45
// wow: order of field declaration matters here, gcc glitch?
46
size_t
m_size
= 0;
47
};
static_vector
Definition
static_vector.h:4
static_vector::m_size
size_t m_size
Definition
static_vector.h:46
static_vector::get
T & get(size_t i)
Definition
static_vector.h:35
static_vector::add
T * add(const T &value)
Definition
static_vector.h:21
static_vector::find
T * find(const TSearch &search) const
Definition
static_vector.h:11
static_vector::getCount
size_t getCount() const
Definition
static_vector.h:39
static_vector::clear
void clear()
Definition
static_vector.h:6
static_vector::m_storage
T m_storage[TSlots]
Definition
static_vector.h:44
Generated on Sat Sep 27 2025 00:10:07 for rusEFI by
1.9.8