如何检查成员函数在C++17中是否不可抛出?
我知道我的类C有一个名为f的成员函数,并且想知道它是否可以用int作为参数进行调用。
#include <type_traits>
struct C{
void f(int){}
};
int main(){
// How to use is_nothrow_invocable_v???
static_assert(std::is_nothrow_invocable_v< &C::f, int >);
}发布于 2017-05-30 19:02:29
您可以使用下列之一:
noexcept(std::declval<C>().f(42))或
std::is_nothrow_invocable_v<decltype(&C::f), C, int>注意:您需要一个实例来调用成员函数。
https://stackoverflow.com/questions/44269678
复制相似问题