【发布时间】:2016-02-13 09:49:29
【问题描述】:
在函数模板的重载解析期间,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
{ ; }
};
int
main()
{
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> 的任何谓词。通常如何处理接受可变参数模板参数包和 SFINAE 的 c-tors?是否存在僵局和固有的语言缺陷?
【问题讨论】:
-
这是什么编译器?
-
@ThomasMcLeod clang 3.7
-
@ThomasMcLeod g++ 给出了早期的硬错误(在 c-tor 本身而不是 SFINAE 中)。
标签: c++ c++11 constructor c++14 sfinae