11 #include <type_traits> 13 #include "quill/core/Attributes.h" 14 #include "quill/core/Common.h" 15 #include "quill/core/QuillError.h" 21 template <
typename T,
size_t N>
26 static_assert(std::is_trivially_copyable_v<value_type>,
"value_type must be trivially copyable");
30 for (
size_t i = 0; i < _capacity; ++i)
32 _storage.inline_buffer[i] = value_type{};
40 delete[] _storage.heap_buffer;
55 if (_size == _capacity)
57 size_t const new_capacity = _capacity * 2;
58 auto* new_data =
new value_type[new_capacity];
60 if (QUILL_UNLIKELY(new_capacity <= _capacity))
63 QuillError{
"This unreachable code is here only to suppress gcc false positive warnings"});
69 for (
size_t i = 0; i < _size; ++i)
71 new_data[i] = _storage.inline_buffer[i];
76 for (
size_t i = 0; i < _size; ++i)
78 new_data[i] = _storage.heap_buffer[i];
80 delete[] _storage.heap_buffer;
83 _storage.heap_buffer = new_data;
84 _capacity = new_capacity;
89 _storage.inline_buffer[_size] = value;
93 _storage.heap_buffer[_size] = value;
104 QUILL_NODISCARD QUILL_ATTRIBUTE_HOT value_type
operator[](
size_t index)
const 106 #if defined(__GNUC__) || defined(__clang__) || defined(__MINGW32__) 107 #pragma GCC diagnostic push 108 #pragma GCC diagnostic ignored "-Warray-bounds" 111 if (QUILL_UNLIKELY(index >= _size))
113 QUILL_THROW(
QuillError{
"index out of bounds"});
118 return _storage.inline_buffer[index];
122 return _storage.heap_buffer[index];
125 #if defined(__GNUC__) || defined(__clang__) || defined(__MINGW32__) 127 #pragma GCC diagnostic pop 136 if (QUILL_UNLIKELY(index >= _size))
138 QUILL_THROW(
QuillError{
"index out of bounds"});
143 _storage.inline_buffer[index] = value;
147 _storage.heap_buffer[index] = value;
151 QUILL_NODISCARD QUILL_ATTRIBUTE_HOT
size_t size()
const noexcept {
return _size; }
152 QUILL_NODISCARD
size_t capacity()
const noexcept {
return _capacity; }
153 QUILL_ATTRIBUTE_HOT
void clear() noexcept { _size = 0; }
158 value_type inline_buffer[N];
159 value_type* heap_buffer;
172 "SizeCacheVector should not exceed a cache line");
QUILL_ATTRIBUTE_HOT value_type push_back(value_type value)
Push back a new element.
Definition: InlinedVector.h:53
QUILL_ATTRIBUTE_HOT void assign(size_t index, value_type value)
Assign value at index.
Definition: InlinedVector.h:134
Definition: InlinedVector.h:22
QUILL_NODISCARD QUILL_ATTRIBUTE_HOT value_type operator[](size_t index) const
Access element.
Definition: InlinedVector.h:104
Setups a signal handler to handle fatal signals.
Definition: BackendManager.h:24
custom exception
Definition: QuillError.h:45