Using x::optional_arg_or

#include <x/optional_args.H>

struct optional_coords {

    int x;
    int y;

    optional_coords(int x, int y) : x{x}, y{y} {}

struct optional_size {
    int w;
    int h;

    optional_size(int w, int h) : w{w}, h{h} {}


void adjust_pos_or_size(x::optional_args<optional_coords, optional_size> &args)
    std::optional<optional_coords> default_coords;
    std::optional<optional_size> default_size;

    optional_coords &coords=x::optional_arg_or<optional_coords>(
        args, default_coords, 0, 0

    optional_size &coords=x::optional_arg_or<optional_size>(
        args, default_size, 0, 0

x::optional_arg_or() returns the constructed option using x::optional_arg(). The second parameter is a default constructed instance of the corresponding x::optional type, which is used to construct an instance of the default value of type if the corresponding option in the x::optional_args does not exist.

x::optional_arg returns a reference to the type, either to the constructed type in the x::optional_args, or in the x::optional default value. The default value gets emplace()d into the x::optional<type> parameter, with any additional parameters getting forwarded to emplace().

The above example returns the optional_coords and optional_size from the args, or from the corresponding std::optional value, passing a pair of goose eggs to the optional values' constructors, if they're used.

Passing a constant x::optional_args returns a reference to a constant object. A reference to a constant object always gets returned from a x::optional_argconstrefs, even a mutable one.