Retrieving optional arguments

void adjust_pos_or_size(const x::optional_args<optional_coords, optional_size> &args)
{
   const std::optional<optional_coords> &c=x::optional_arg<optional_coords>(args);
   const std::optional<optional_coords> &c=x::optional_arg<optional_size>(args);

The x::optional_arg template retrieves (a reference to) the specified std::optional value. It's analogous to std::get for std::tuples. The optional value indicates whether this value was passed to x::optional_args's constructor.

   const auto &c=x::optional_arg<0>(args);

Similar to std::get, x::optional_arg's type parameter works only when the type is a unique x::optional_args template parameter. Like std::get, a constant numerical x::optional_arg template parameter specifies an x::optional_args type by its 0-based index, and this works when the same type appears two or more times.

Note

Two or more consecutive instances of the same type as x::optional_args have the following results:

  • None of the option values, for this type, get set if the corresponding values get passed to x::optional_args's constructor.

  • The first value of the same type (or which can be implicitly converted to the type) initializes the first optional value of this type.

  • The next, immediately following, constructor parameter value initializes the next optional value of this type, and so on.

  • Effectively, the parameter values to the constructor initialize the corresponding optional values on a first come-first serve basis.

  • If any parameter values are left, after initializing all optional value, the program is ill-formed.