Skip to content

Commit 74644aa

Browse files
committed
include/any.h: avoid using std::aligned_storage_t
std::aligned_storage_t was deprecated in C++23, to be prepared for it, let's use alignas for the same behavior. because we do not always pass a power-of-2 number to `immobile_any`, while `alignas()` requires an alignment of power of 2. so we use `std::bit_ceil()` to calculate the minimum alignment greater or equal to the given number. Signed-off-by: Kefu Chai <[email protected]>
1 parent 379637e commit 74644aa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/include/any.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define INCLUDE_STATIC_ANY
1717

1818
#include <any>
19+
#include <bit>
1920
#include <cstddef>
2021
#include <initializer_list>
2122
#include <memory>
@@ -491,6 +492,11 @@ any_cast(_any::base<U, V>&& a) {
491492
throw std::bad_any_cast();
492493
}
493494

495+
template<std::size_t S, std::size_t Alignment = std::bit_ceil(S)>
496+
struct alignas(Alignment) aligned_storage {
497+
std::byte data[S];
498+
};
499+
494500
// `immobile_any`
495501
// ==============
496502
//
@@ -508,12 +514,11 @@ any_cast(_any::base<U, V>&& a) {
508514
// invoked when they throw.
509515
//
510516
template<std::size_t S>
511-
class immobile_any : public _any::base<immobile_any<S>,
512-
std::aligned_storage_t<S>> {
513-
using base = _any::base<immobile_any<S>, std::aligned_storage_t<S>>;
517+
class immobile_any : public _any::base<immobile_any<S>, aligned_storage<S>> {
518+
using base = _any::base<immobile_any<S>, aligned_storage<S>>;
514519
friend base;
515520

516-
using _any::base<immobile_any<S>, std::aligned_storage_t<S>>::storage;
521+
using _any::base<immobile_any<S>, aligned_storage<S>>::storage;
517522

518523
// Superclass requirements!
519524
// ------------------------

0 commit comments

Comments
 (0)