【问题标题】:Variable args SFINAE default constructor works in clang, but fails in Visual Studio 2015变量 args SFINAE 默认构造函数在 clang 中工作,但在 Visual Studio 2015 中失败
【发布时间】: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&lt;..&gt;::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


【解决方案1】:

正如 deviantfan 所说 - 实际上 MS 没有声称 Visual Studio 2015 实际上完全支持 SFINAE,所以这似乎不是一个特定的错误,只是 VS2015 不符合 C++11。

https://msdn.microsoft.com/en-us/library/hh567368.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多