I am wondering whether there would be a trick to simplify the writing of a trait to return whether a type is a noexcept
function. Currently my implementation is the following, and it just lists all the possibilities, one by one. Could it be written in a simpler way using standard C++20
?
// Default
template <class>
struct is_noexcept_function: std::false_type {};
// Variable template
template <class T>
inline constexpr bool is_noexcept_function_v
= is_noexcept_function<T>::value;
// Noexcept functions
template <class R, class... Args>
struct is_noexcept_function<R(Args...) noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args...) const noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args...) volatile noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args...) const volatile noexcept>: std::true_type {};
// Noexcept lvalue-ref-qualified functions
template <class R, class... Args>
struct is_noexcept_function<R(Args...) & noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args...) const & noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args...) volatile & noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args...) const volatile & noexcept>: std::true_type {};
// Noexcept rvalue-ref-qualified functions
template <class R, class... Args>
struct is_noexcept_function<R(Args...) && noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args...) const && noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args...) volatile && noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args...) const volatile && noexcept>: std::true_type {};
// Noexcept variadic functions
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) const noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) volatile noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) const volatile noexcept>: std::true_type {};
// Noexcept lvalue-ref-qualified variadic functions
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) & noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) const & noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) volatile & noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) const volatile & noexcept>: std::true_type {};
// Noexcept rvalue-ref-qualified variadic functions
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) && noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) const && noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) volatile && noexcept>: std::true_type {};
template <class R, class... Args>
struct is_noexcept_function<R(Args..., ...) const volatile && noexcept>: std::true_type {};
std::is_nothrow_invocable
? – Himyarite