How can I detect whether a template argument is a noexcept function?

泄露秘密 提交于 2019-12-05 01:42:45
user2296177

From: http://en.cppreference.com/w/cpp/language/noexcept_spec

The noexcept-specification is not a part of the function type. (until C++17).

Currently, template deduction will not produce the correct results since the noexcept specifier is not part of a function's type; template type deduction will not work until C++17. My way of detecting whether a function is noexcept will be valid in C++17 as will this answer's way.

You can use the noexcept operator, which takes an expression and produces true if that expression is noexcept.

Untested, but this might work for your use case.

return [&] () noexcept(noexcept(std::forward<F>( f )( std::forward<FArgs>( f_args )... )))
    -> std::result_of_t<F( FArgs... )>
{
    return std::forward<F>( f )( std::forward<FArgs>( f_args )... );
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!