When I declare a variable function<void(const Foo&)>
, the compiler still lets me assign a lambda that accepts a value:
function<void(const Foo&)> handler;
handler = [](Foo f){};
(cfr. also http://cpp.sh/5dsp)
So when the handler is called, a copy will be made. What section of the standard allows this? Is there a way I can flag the client code that this will be a problem (some static_assert of sorts?)?
Per [func.wrap.func.con]
has a
with the following remark:
where
So you can assign to an
std::function<R(ArgTypes...)>
any function callable withArgTypes...
and returning something implicitly convertible toR
.I don't see how to prevent this short of wrapping an
std::function
in something more limited.