草庐IT

NoExceptDelegate

全部标签

c++ - 在 std::function 上强制执行 "noexcept"?

此代码编译并运行,抛出int:#includevoidr(std::functionf){f();}voidfoo(){throw1;}intmain(){r(foo);}但是我希望编译器拒绝r(foo);行,因为r应该只传递一个noexcept函数。noexcept说明符似乎被忽略了。有什么办法可以实现吗?编辑:这个问题不同于Isknowledgeaboutnoexcept-nesssupposedtobeforwardedwhenpassingaroundafunctionpointer?因为我要求补救措施,特别是在std::function的情况下。