Enforce “noexcept” on std::function?
问题 This code compiles and runs, throwing the int : #include <functional> void r( std::function<void() noexcept> f ) { f(); } void foo() { throw 1; } int main() { r(foo); } However I would like the compiler to reject the line r(foo); because r should only be passed a noexcept function. The noexcept specifier appears to be ignored. Is there any way to achieve that? Edit: This question is different to Is knowledge about noexcept-ness supposed to be forwarded when passing around a function pointer?