Skip to content

Commit 3c8f796

Browse files
authored
Merge pull request ceph#63027 from tchaikov/any-alignas
include/any.h: avoid using std::aligned_storage_t Reviewed-by: Adam Emerson <[email protected]>
2 parents 2248940 + 74644aa commit 3c8f796

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)