2#ifndef LIBSBX_MEMORY_ALIGNED_STORAGE_HPP_
3#define LIBSBX_MEMORY_ALIGNED_STORAGE_HPP_
11template<std::
size_t Size, std::
size_t Alignment>
14 alignas(Alignment) std::byte data[Size];
18template<std::
size_t Size, std::
size_t Alignment>
21template<
typename Type>
24 struct alignas(alignof(Type))
type {
25 std::byte data[
sizeof(Type)];
29template<
typename Type>
40template<
typename Type>
45 using value_type = Type;
57 template<
typename... Args>
58 requires (std::is_constructible_v<Type, Args...>)
59 auto construct(Args&&... args) -> Type* {
60 return std::construct_at(_ptr(), std::forward<Args>(args)...);
63 auto destroy()
noexcept ->
void {
64 std::destroy_at(_ptr());
67 auto get()
noexcept -> Type* {
71 auto get()
const noexcept ->
const Type* {
75 auto operator*()
noexcept -> Type& {
79 auto operator*()
const noexcept ->
const Type& {
85 auto _ptr()
noexcept -> Type* {
86 return std::launder(
reinterpret_cast<Type*
>(&_storage));
89 auto _ptr()
const noexcept ->
const Type* {
90 return std::launder(
reinterpret_cast<const Type*
>(&_storage));
93 storage_for_t<Type> _storage;
A class that allows for the manual construction and destruction of an object of type Type.
Definition: aligned_storage.hpp:41
Definition: aligned_storage.hpp:13
Definition: aligned_storage.hpp:12
Definition: aligned_storage.hpp:24
Definition: aligned_storage.hpp:22