1 //===--- AlignOf.h - Portable calculation of type alignment -----*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines the AlignedCharArrayUnion class.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_SUPPORT_ALIGNOF_H
14 #define LLVM_SUPPORT_ALIGNOF_H
16 #include "llvm/Support/Compiler.h"
23 template <typename T
, typename
... Ts
> class AlignerImpl
{
25 AlignerImpl
<Ts
...> rest
;
26 AlignerImpl() = delete;
29 template <typename T
> class AlignerImpl
<T
> {
31 AlignerImpl() = delete;
34 template <typename T
, typename
... Ts
> union SizerImpl
{
36 SizerImpl
<Ts
...> rest
;
39 template <typename T
> union SizerImpl
<T
> { char arr
[sizeof(T
)]; };
40 } // end namespace detail
42 /// A suitably aligned and sized character array member which can hold elements
45 /// These types may be arrays, structs, or any other types. This exposes a
46 /// `buffer` member which can be used as suitable storage for a placement new of
47 /// any of these types.
48 template <typename T
, typename
... Ts
> struct AlignedCharArrayUnion
{
49 alignas(::llvm::detail::AlignerImpl
<T
, Ts
...>) char buffer
[sizeof(
50 llvm::detail::SizerImpl
<T
, Ts
...>)];
53 } // end namespace llvm
55 #endif // LLVM_SUPPORT_ALIGNOF_H