Macro Subspace :: sus_class_trivially_relocatable_if_types

Mark a class as trivially relocatable if the types passed as arguments are all trivially relocatable.

This macro is most useful in templates where the template parameter types are unknown and can be passed to the macro to determine if they are trivially relocatable.

Avoid marking the class with the [[clang::trivial_abi]] attribute, as when the class is not trivially relocatable (since a subtype is not trivially relocatable), it can cause memory safety bugs and Undefined Behaviour.

Use the TriviallyRelocatable concept to determine if a type is trivially relocatable, and to test with static_assert that types are matching what you are expecting. This allows containers to optimize their implementations when relocating the type in memory.

Macro Style
sus_class_trivially_relocatable asserts all param types are trivially relocatable
sus_class_trivially_relocatable_if_types is conditionally trivially relocatable if all param types are
sus_class_trivially_relocatable_if is conditionally trivially relocatable if the condition is true
sus_class_trivially_relocatable_unchecked is trivially relocatable without any condition or assertion

Example

template <class T>
struct S {
  Thing<i32> thing;
  i32 more;

  sus_class_trivially_relocatable_if_types(
      unsafe_fn,
      decltype(thing),
      decltype(more));
};