This pattern is licensed under the CC0 Public Domain Dedication.
Allow argument values to be omitted when calling a function.
foo, on lines 3–6, takes three arguments, two of which
the Library Fundamentals TS). This allows the value of those
arguments to be omitted, as shown on lines 10–13, where
std::nullopt represents no value.
This approach is more expressive than using pointers and
A related technique is the use of default arguments, which allow
arguments to be omitted entirely, but only from the end of the
If you are constructing an object with a complex combinatorial set of optional arguments, consider using the builder pattern.