12 #include <type_traits> 14 #include "quill/core/Attributes.h" 15 #include "quill/core/Common.h" 16 #include "quill/core/QuillError.h" 18 #if defined(__GNUC__) && !defined(__clang__) 19 #pragma GCC diagnostic push 20 #pragma GCC diagnostic ignored "-Warray-bounds" 21 #pragma GCC diagnostic ignored "-Wstringop-overflow" 22 #elif defined(__clang__) 23 #pragma GCC diagnostic push 24 #pragma GCC diagnostic ignored "-Warray-bounds" 25 #elif defined(_WIN32) && defined(_MSC_VER) 27 #pragma warning(disable : 4789) 35 template <
typename T,
size_t N>
40 static_assert(std::is_trivially_copyable_v<value_type>,
"value_type must be trivially copyable");
44 for (
size_t i = 0; i < _capacity; ++i)
46 _storage.inline_buffer[i] = value_type{};
54 delete[] _storage.heap_buffer;
69 if (_size == _capacity)
71 size_t const new_capacity = _capacity * 2;
72 auto* new_data =
new value_type[new_capacity];
74 if (QUILL_UNLIKELY(new_capacity <= _capacity))
77 QuillError{
"This unreachable code is here only to suppress gcc false positive warnings"});
84 std::memcpy(new_data, _storage.inline_buffer, _size *
sizeof(value_type));
89 std::memcpy(new_data, _storage.heap_buffer, _size *
sizeof(value_type));
90 delete[] _storage.heap_buffer;
93 _storage.heap_buffer = new_data;
94 _capacity = new_capacity;
99 _storage.inline_buffer[_size] = value;
103 _storage.heap_buffer[_size] = value;
114 QUILL_ATTRIBUTE_HOT value_type
operator[](
size_t index)
const 116 if (QUILL_UNLIKELY(index >= _size))
118 QUILL_THROW(
QuillError{
"index out of bounds"});
123 return _storage.inline_buffer[index];
127 return _storage.heap_buffer[index];
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");
177 #if defined(__GNUC__) && !defined(__clang__) 178 #pragma GCC diagnostic pop 179 #elif defined(__clang__) 180 #pragma GCC diagnostic pop 181 #elif defined(_WIN32) && defined(_MSC_VER) QUILL_ATTRIBUTE_HOT value_type push_back(value_type value)
Push back a new element.
Definition: InlinedVector.h:67
QUILL_ATTRIBUTE_HOT value_type operator[](size_t index) const
Access element.
Definition: InlinedVector.h:114
QUILL_ATTRIBUTE_HOT void assign(size_t index, value_type value)
Assign value at index.
Definition: InlinedVector.h:134
Definition: InlinedVector.h:36
Setups a signal handler to handle fatal signals.
Definition: BackendManager.h:24
custom exception
Definition: QuillError.h:45