c – SFINAE和noexcept说明符

c – SFINAE和noexcept说明符,第1张

概述在功能模板的重载解析过程中,noexcept说明符括号中的表达式是否参与SFINAE? 我想为聚合创建一个包装器,并希望std :: is_constructible谓词正常工作: template< typename type >struct embrace : type{ template< typename ...arguments > embrace(argu 在功能模板的重载解析过程中,noexcept说明符括号中的表达式是否参与SFINAE?

我想为聚合创建一个包装器,并希望std :: is_constructible谓词正常工作:

template< typename type >struct embrace    : type{    template< typename ...arguments >    embrace(arguments &&... _arguments) noexcept(noexcept(type{std::forward< arguments >(_arguments)...}))        : type{std::forward< arguments >(_arguments)...} // braces     { ; }};intmain(){    struct S { int i; double j; }; // aggregate    using E = embrace< S >;    E b(1,1.0); // "parentheses"-constructible => can be used as usual types    b.i = 1; b.j = 2.0; // accessible    static_assert(std::is_constructible< E,int,double >{});    static_assert(std::is_constructible< E,struct B >{}); // want hard error here    return EXIT_SUCCESS;}

但是我尝试在noexcept规范中使用noexcept *** 作符来启用SFINAE失败,并且模板构造函数接受传递给它的所有内容.构造函数如何被限制?

标准不允许专门从< type_traits&gt ;.的任何谓词.如何处理接受可变模板参数包和SFINAE的转换器?是否有僵局和固有的语言缺陷?

解决方法 SFINAE根本不适用于异常规范,无论是否是功能类型的一部分.

见[temp.deduct] / 7中的注释:

The substitution occurs in all types and Expressions that are used in
the function type and in template parameter declarations. The
Expressions include not only constant Expressions such as those that
appear in array bounds or as nontype template arguments but also
general Expressions (i.e.,non-constant Expressions) insIDe sizeof,
decltype,and other contexts that allow non-constant Expressions. The
substitution proceeds in lexical order and stops when a condition that
causes deduction to fail is encountered. [ Note: The equivalent
substitution in exception specifications is done only when the
exception-specification is instantiated,at which point a program is ill-formed if the substitution results in an invalID type or
Expression. —end note ]

P0012R1 didn’t change anything在这方面.

Piotr的答案涵盖了您的代码的修复.

总结

以上是内存溢出为你收集整理的c – SFINAE和noexcept说明符全部内容,希望文章能够帮你解决c – SFINAE和noexcept说明符所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1255990.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存