加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 变量args SFINAE默认构造函数在clang中工作,但在Visual Stu

发布时间:2020-12-16 07:16:08 所属栏目:百科 来源:网络整理
导读:任何人都知道这段代码是坏的还是VS有错误或者Clang是否允许? 我认为我的构造函数应该不接受任何参数并传递enable_if检查 – 但在某处VS说“不”. Visual Studio 2015 Update 2出现以下错误: source_file.cpp(##): error C2512: 'Foo::Foo': no appropriate
任何人都知道这段代码是坏的还是VS有错误或者Clang是否允许?

我认为我的构造函数应该不接受任何参数并传递enable_if检查 – 但在某处VS说“不”.

Visual Studio 2015 Update 2出现以下错误:

source_file.cpp(##): error C2512: 'Foo::Foo': no appropriate default constructor available

clang live: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;  
}

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读