stdalign


1. Aligning a structure to the size of a double:

struct AlignedStruct {
  double d;
  int i;
};

static_assert(alignof(AlignedStruct) == alignof(double));

2. Aligning a union to the size of its widest member:

union AlignedUnion {
  double d;
  int i;
};

static_assert(alignof(AlignedUnion) == alignof(double));

3. Aligning an array to the size of its elements:

int a[10];

static_assert(alignof(a) == alignof(int));

4. Aligning a pointer to the size of the type it points to:

5. Aligning a function pointer to the size of a function pointer:

6. Aligning a member function pointer to the size of a member function pointer:

7. Aligning a data member to a specific alignment:

8. Aligning a base class to a specific alignment:

9. Aligning a virtual base class to a specific alignment:

10. Aligning a function parameter to a specific alignment:

11. Aligning a function return value to a specific alignment:

12. Aligning a local variable to a specific alignment:

13. Aligning a catch clause to a specific alignment:

14. Aligning a lambda capture to a specific alignment:

15. Aligning a template parameter to a specific alignment:

16. Aligning a function template parameter to a specific alignment:

17. Aligning a class template parameter to a specific alignment:

18. Aligning a struct template parameter to a specific alignment:

19. Aligning an union template parameter to a specific alignment:

20. Aligning an enum template parameter to a specific alignment:

21. Aligning a typedef to a specific alignment:

22. Using std::align to align a pointer:

23. Using std::aligned_storage to allocate aligned memory:

24. Using std::aligned_union to declare an aligned union:

25. Using std::aligned_ptr to declare an aligned pointer:

26. Using std::aligned_unique_ptr to declare an aligned unique pointer:

27. Using std::aligned_shared_ptr to declare an aligned shared pointer:

28. Aligning a struct to the size of its largest member:

29. Aligning a union to the size of its widest member: