Why can I pass a value-accepting callable to a reference-accepting std::function?

Viewed 205

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?)?

1 Answers
Related