no除了不被腐烂去除

Tyk*_*ker 0 c++ c++17

为什么不std::decay从函数指针中删除noexcept说明符?

例如,这符合c ++ 17

#include <type_traits>

template<typename>
struct is_noexcept {};

template<typename R, typename ... Arg>
struct is_noexcept<R(*)(Arg...)> : public std::false_type {};

template<typename R, typename ... Arg>
struct is_noexcept<R(*)(Arg...) noexcept> : public std::true_type {};

void test() noexcept {}

int main(){
    void (*b)() noexcept = test;
    static_assert(is_noexcept<decltype(b)>::value);
    static_assert(is_noexcept<std::decay<decltype(b)>::type>::value);
}
Run Code Online (Sandbox Code Playgroud)

Bri*_*ian 5

std::decay类型的转换特性来执行当表达通过值传递给函数模板发生的转换:

template <class T>
void f(T);

int main() {
    f(expr); // T is deduced to std::decay_t<decltype(expr)>
}
Run Code Online (Sandbox Code Playgroud)

一种这样的转换是函数到指针的转换,因为函数不能通过值传递.由于noexcept类型安全原因,函数到指针转换保留了函数的规范,因此std::decay也是如此.