Define SEQUANT_DESIGNATED_INIT_ONLY

Define Documentation

SEQUANT_DESIGNATED_INIT_ONLY

Declares a hidden first member of an Options-style aggregate that makes positional (non-designated) aggregate initialization ill-formed, so that every call site must name the fields it sets:

struct LSTOptions {
  SEQUANT_DESIGNATED_INIT_ONLY;
  bool unitary = false;
  bool use_connected_form = false;
};
Positional aggregate init is otherwise legal C++, and it is not merely unreadable: reordering the fields, or changing the meaning of one while keeping its position, silently reinterprets any positional caller instead of failing to compile. Designated initializers do not have that failure mode — renaming a field is a hard error at every call site that sets it.

Rejected: Opts{a, b} and Opts{{}, a, b}. Still accepted, and unaffected: Opts{}, Opts{.field = a}, copy and move, Opts as a defaulted function parameter (f(Opts opts = {})), and use in constant expressions.

Note

Must be the first member, and requires C++20 designated initializers.

Note

The member is declared [[no_unique_address]], so the aggregate’s size is unchanged, and it stays an aggregate and trivially copyable.