使用VS2017 RC但Variadic模板包扩展失败,但VS2015没有

时间:2017-02-21 00:27:26

标签: c++ variadic-templates

测试程序使用VS2015进行编译,但不使用VS2017 RC进行编译。以下是使用VS2017 RC编译测试程序时遇到的错误:

/* main.cpp */
#include <type_traits>

template <typename T>
struct A_impl
{
    using type = std::false_type;
};

template <typename T>
using A = typename A_impl<T>::type;

template <bool... B>
struct logic_helper;

template <bool... B>
using none_t = std::is_same<logic_helper<B...>, logic_helper<(B && false)...>>;

template <typename... C>
struct Foo
{
    // Compile error:
    // error C3520: 'C': parameter pack must be expanded in this context
    using FooType = none_t<A<C>::value...>;
};

int main()
{
    Foo<int, int, int> foo;
    return 0;
}

我想知道为什么最新的Visual Studio无法编译代码,而旧版本没有问题。如果可能,是否有针对VS2017 RC的编译错误的解决方案?

1 个答案:

答案 0 :(得分:0)

我找到了问题的解决方法,但我仍然无法理解为什么编译器会抱怨我的第一种方法:

template <typename... C>
struct Foo
{
    // Workaround
    using FooType2 = logic_helper<A<C>::value...>;
    using FooType3 = logic_helper<(A<C>::value && false)...>;
    using FooType4 = std::is_same<FooType2, FooType3>;
};