|
1 | | -// itlib-static-vector v1.07 |
| 1 | +// itlib-static-vector v1.08 |
2 | 2 | // |
3 | 3 | // std::vector-like class with a fixed capacity |
4 | 4 | // |
5 | 5 | // SPDX-License-Identifier: MIT |
6 | 6 | // MIT License: |
7 | 7 | // Copyright(c) 2016-2019 Chobolabs Inc. |
8 | | -// Copyright(c) 2020-2023 Borislav Stanimirov |
| 8 | +// Copyright(c) 2020-2026 Borislav Stanimirov |
9 | 9 | // |
10 | 10 | // Permission is hereby granted, free of charge, to any person obtaining |
11 | 11 | // a copy of this software and associated documentation files(the |
|
29 | 29 | // |
30 | 30 | // VERSION HISTORY |
31 | 31 | // |
| 32 | +// 1.08 (2026-02-05) Drop use of deprecated std::aligned_storage |
32 | 33 | // 1.07 (2023-04-06) Added resize with initializer |
33 | 34 | // 1.06 (2023-01-17) Shim allocator arg to constructors for template code |
34 | 35 | // All standard overloads of insert |
@@ -289,13 +290,13 @@ struct static_vector |
289 | 290 | const_reference at(size_type i) const |
290 | 291 | { |
291 | 292 | I_ITLIB_STATIC_VECTOR_BOUNDS_CHECK(i); |
292 | | - return *reinterpret_cast<const T*>(m_data + i); |
| 293 | + return m_data[i].data; |
293 | 294 | } |
294 | 295 |
|
295 | 296 | reference at(size_type i) |
296 | 297 | { |
297 | 298 | I_ITLIB_STATIC_VECTOR_BOUNDS_CHECK(i); |
298 | | - return *reinterpret_cast<T*>(m_data + i); |
| 299 | + return m_data[i].data; |
299 | 300 | } |
300 | 301 |
|
301 | 302 | const_reference operator[](size_type i) const |
@@ -330,12 +331,12 @@ struct static_vector |
330 | 331 |
|
331 | 332 | const_pointer data() const noexcept |
332 | 333 | { |
333 | | - return reinterpret_cast<const T*>(m_data); |
| 334 | + return &m_data[0].data; |
334 | 335 | } |
335 | 336 |
|
336 | 337 | pointer data() noexcept |
337 | 338 | { |
338 | | - return reinterpret_cast<T*>(m_data); |
| 339 | + return &m_data[0].data;; |
339 | 340 | } |
340 | 341 |
|
341 | 342 | // iterators |
@@ -669,7 +670,10 @@ struct static_vector |
669 | 670 | return position; |
670 | 671 | } |
671 | 672 |
|
672 | | - typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type m_data[Capacity]; |
| 673 | + struct aligned_storage { |
| 674 | + T data; |
| 675 | + }; |
| 676 | + aligned_storage m_data[Capacity]; |
673 | 677 | size_t m_size = 0; |
674 | 678 | }; |
675 | 679 |
|
|
0 commit comments