Skip to content

Commit a23e2ee

Browse files
committed
[static_vector][small_vector] drop usage of std::aligned_storage deprecated in C++23
1 parent a51116c commit a23e2ee

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

include/itlib/small_vector.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// itlib-small-vector v2.06
1+
// itlib-small-vector v2.07
22
//
33
// std::vector-like class with a static buffer for initial capacity
44
//
55
// SPDX-License-Identifier: MIT
66
// MIT License:
77
// Copyright(c) 2016-2018 Chobolabs Inc.
8-
// Copyright(c) 2020-2025 Borislav Stanimirov
8+
// Copyright(c) 2020-2026 Borislav Stanimirov
99
//
1010
// Permission is hereby granted, free of charge, to any person obtaining
1111
// a copy of this software and associated documentation files(the
@@ -29,6 +29,7 @@
2929
//
3030
// VERSION HISTORY
3131
//
32+
// 2.07 (2026-02-05) Drop use of deprecated std::aligned_storage
3233
// 2.06 (2025-03-28) Minor: Add missing header <cstdint>
3334
// 2.05 (2024-03-06) Minor: Return bool from shrink_to_fit
3435
// 2.04 (2022-04-29) Minor: Disable MSVC warning for constant conditional
@@ -153,7 +154,7 @@
153154
//
154155
#pragma once
155156

156-
#include <type_traits>
157+
//#include <type_traits>
157158
#include <cstddef>
158159
#include <cstdint>
159160
#include <memory>
@@ -716,12 +717,12 @@ struct small_vector : private Alloc
716717
private:
717718
const T* static_begin_ptr() const
718719
{
719-
return reinterpret_cast<const_pointer>(m_static_data + 0);
720+
return &m_static_data[0].data;
720721
}
721722

722723
T* static_begin_ptr()
723724
{
724-
return reinterpret_cast<pointer>(m_static_data + 0);
725+
return &m_static_data[0].data;
725726
}
726727

727728
void destroy_all()
@@ -1005,7 +1006,10 @@ struct small_vector : private Alloc
10051006
pointer m_begin; // begin either points to m_static_data or to new memory
10061007
pointer m_end;
10071008
size_t m_capacity;
1008-
typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type m_static_data[StaticCapacity];
1009+
struct aligned_storage {
1010+
T data;
1011+
};
1012+
aligned_storage m_static_data[StaticCapacity];
10091013
};
10101014

10111015
template<typename T,

include/itlib/static_vector.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// itlib-static-vector v1.07
1+
// itlib-static-vector v1.08
22
//
33
// std::vector-like class with a fixed capacity
44
//
55
// SPDX-License-Identifier: MIT
66
// MIT License:
77
// Copyright(c) 2016-2019 Chobolabs Inc.
8-
// Copyright(c) 2020-2023 Borislav Stanimirov
8+
// Copyright(c) 2020-2026 Borislav Stanimirov
99
//
1010
// Permission is hereby granted, free of charge, to any person obtaining
1111
// a copy of this software and associated documentation files(the
@@ -29,6 +29,7 @@
2929
//
3030
// VERSION HISTORY
3131
//
32+
// 1.08 (2026-02-05) Drop use of deprecated std::aligned_storage
3233
// 1.07 (2023-04-06) Added resize with initializer
3334
// 1.06 (2023-01-17) Shim allocator arg to constructors for template code
3435
// All standard overloads of insert
@@ -289,13 +290,13 @@ struct static_vector
289290
const_reference at(size_type i) const
290291
{
291292
I_ITLIB_STATIC_VECTOR_BOUNDS_CHECK(i);
292-
return *reinterpret_cast<const T*>(m_data + i);
293+
return m_data[i].data;
293294
}
294295

295296
reference at(size_type i)
296297
{
297298
I_ITLIB_STATIC_VECTOR_BOUNDS_CHECK(i);
298-
return *reinterpret_cast<T*>(m_data + i);
299+
return m_data[i].data;
299300
}
300301

301302
const_reference operator[](size_type i) const
@@ -330,12 +331,12 @@ struct static_vector
330331

331332
const_pointer data() const noexcept
332333
{
333-
return reinterpret_cast<const T*>(m_data);
334+
return &m_data[0].data;
334335
}
335336

336337
pointer data() noexcept
337338
{
338-
return reinterpret_cast<T*>(m_data);
339+
return &m_data[0].data;;
339340
}
340341

341342
// iterators
@@ -669,7 +670,10 @@ struct static_vector
669670
return position;
670671
}
671672

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];
673677
size_t m_size = 0;
674678
};
675679

0 commit comments

Comments
 (0)