struct bigparam { // ... bigparam(const bigparam &)=delete; }; void some_function(const x::optional_argconstrefs< ..., bigparam, ...> &) { // ... some_function(..., big_param{....}, ...);
The x::optional_argconstrefs
template is a convenient wrapper that implements
x::optional_args
's variadic
std::optional
values as
std::reference_wrapper
s.
This avoids making copies of individual optional
parameters when they cannot be constructed or move-constructed
in place, or the copy
cannot be elided, for some reason.
Requirements for safely using
x::optional_argconstrefs
:
Optionally delete each parameter's copy-constructor, to ensure that no copies get made.
Explicitly pass the corresponding parameters as temporaries in the function call. The lifetime of temporaries spans the function call itself, and the temporary gets destroyed at the conclusion of the function call.
Alternatively, construct a parameter explicitly, and pass it
as a plain reference, in the function call.
Do not try to implicitly construct a parameter.
This should be ill-formed, as a result of attempting to
initialize std::reference_wrappers
using
const
references of a different type.
The most common example of this would be a
std::string
parameter
that cannot get initialized
from "foo"
. It must be initialized explicitly
as std::string{"foo"}