alignof operator (since C++11)
Min standard notice:
Queries alignment requirements of a type.
# Notes
See alignment for the meaning and properties of the value returned by alignof.
# Example
#include <iostream>
struct Foo
{
int i;
float f;
char c;
};
// Note: alignas(alignof(long double)) below can be
// simplified to alignas(long double) if desired.
struct alignas(alignof(long double)) Foo2
{
// put your definition here
};
struct Empty {};
struct alignas(64) Empty64 {};
#define SHOW(expr) std::cout << #expr << " = " << (expr) << '\n'
int main()
{
SHOW(alignof(char));
SHOW(alignof(int*));
SHOW(alignof(Foo));
SHOW(alignof(Foo2));
SHOW(alignof(Empty));
SHOW(alignof(Empty64));
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| CWG 1305 | C++11 | type-id could not represent a reference to an arraywith an unknown bound but a complete element type | allowed |