Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 未通过衰变去除的异常_C++_C++17 - Fatal编程技术网

C++ 未通过衰变去除的异常

C++ 未通过衰变去除的异常,c++,c++17,C++,C++17,为什么不从函数指针中删除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<typena

为什么不从函数指针中删除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);
}
#包括
模板
结构是{};
模板
结构是_noexcept:public std::false_type{};
模板
结构是_noexcept:public std::true_type{};
void test()noexcept{}
int main(){
无效(*b)()无异常=测试;
静态_断言(is_noexcept::value);
静态_断言(is_noexcept::value);
}

类型转换特性执行表达式按值传递给函数模板时发生的转换:

template <class T>
void f(T);

int main() {
    f(expr); // T is deduced to std::decay_t<decltype(expr)>
}
模板
空隙f(T);
int main(){
f(expr);//T被推导为std::decay\u T
}

其中一种转换是函数到指针的转换,因为函数不能按值传递。出于类型安全原因,函数到指针的转换保留函数的
noexcept
规范,因此
std::detacy
也保留该规范。

类型转换特性执行表达式按值传递给函数模板时发生的转换:

template <class T>
void f(T);

int main() {
    f(expr); // T is deduced to std::decay_t<decltype(expr)>
}
模板
空隙f(T);
int main(){
f(expr);//T被推导为std::decay\u T
}

其中一种转换是函数到指针的转换,因为函数不能按值传递。出于类型安全原因,函数到指针转换保留函数的
noexcept
规范,因此,
std::decay
也可以。

为什么您认为应该这样做?@rubenvb因为decay通常用于从类型中删除说明符。
std::decay
旨在模拟将某个对象作为函数参数传递时发生的情况;数组变为指针,cv限定被剥离,引用被剥离。就是这样。@Tyker被定义为做三件事:将数组分解为指向其第一个元素的指针,从函数(引用)中生成函数指针,或者,正如您所说,删除const/volatile和对象类型可能具有的任何引用限定符。您认为它为什么应该这样做?@rubenvb,因为detaction通常用于从类型中删除说明符。
std::detacy
旨在模拟将某个对象作为函数参数传递时发生的情况;数组变为指针,cv限定被剥离,引用被剥离。就是这样。@Tyker被定义为做三件事:将数组衰减为指向其第一个元素的指针,从函数(引用)中生成函数指针,或者正如您所说的,删除const/volatile和对象类型可能具有的任何引用限定符。谢谢,我不理解
std::decay
谢谢,我不理解
std::decay