【发布时间】:2016-04-21 00:04:40
【问题描述】:
任何人都知道这段代码是否有问题,或者 VS 是否有错误,或者 Clang 是否允许?
我认为我的构造函数不应该接受任何参数并通过 enable_if 检查 - 但是 VS 在某处说“不”。
Visual Studio 2015 Update 2 出现以下错误:
source_file.cpp(##): error C2512: 'Foo::Foo': no appropriate default constructor available
clang 直播:http://rextester.com/VWAI2954
VS 存在错误:http://rextester.com/PTDSS2853
#include <iostream>
#include <deque>
using namespace std;
template <bool... b> struct static_all_of;
// If the first parameter is true, look at the rest of the list
template <bool... tail>
struct static_all_of<true, tail...> : static_all_of<tail...> {};
// if any parameter is false, return false
template <bool... tail>
struct static_all_of<false, tail...> : std::false_type {};
// If there are no parameters left, no false was found so return true
template <> struct static_all_of<> : std::true_type {};
struct Bar{};
struct Foo {
template <class... Things,
std::enable_if_t<static_all_of<std::is_base_of<Bar, std::remove_pointer_t<Things>>::value...>::value, int> = 0>
Foo(Things... stuff){}
};
int main()
{
Foo f;
}
【问题讨论】:
-
原来是 std::remove_pointer_t 位.. 如果我将它切换到
typename std::remove_pointer<..>::type那么它工作正常。 -
在这一点上,如果有人能指出一个特定的 VS 错误或一些文档说我正在做的事情与 VS 不兼容,那就太好了。
-
用 gcc 5.3.1 编译没有问题
-
@xaxxon msdn.microsoft.com/en-us/library/hh567368.aspx 通常将 SFINAE 列为“不”支持,即使在 2015 版中也是如此。...不是“特定错误”,但就是这样。
-
@SamVarshavchik 感谢您的检查。
标签: c++ visual-studio visual-c++ visual-studio-2015