MSVC2015 update 3 variadic template workaround

Visual Studio 2015 update 3 improved support of C++11 much, but I have strange problem and I am searching for workaround.

When compiling variadic-template code with MSVC for template type arguments ("fully defined types") all works good, but if I want to use template template arguments ("partially defined types"), the result becomes incorrect.

#include <iostream>
using namespace std;

template <template<typename> class... TS>
struct PARTIAL {
    static void test(std::ostream& out)
    {
        out << "PARTIAL-PROBLEM" << endl;
    }
};
template <template<typename> class T>
struct PARTIAL<T>{
    static void test(std::ostream& out)
    {out << "PARTIAL-OK-END" << endl;}
};
template <template<typename> class T, template<typename> class... TS>
struct PARTIAL<T, TS...>{
    static void test(std::ostream& out)
    {
        out << "PARTIAL-OK" << endl;
        PARTIAL<TS...>::test(out);
    }
};

template <class... TS>
struct FULL {
    static void test(std::ostream& out)
    {
        out << "FULL-PROBLEM" << endl;
    }
};
template <class T>
struct FULL<T>{
    static void test(std::ostream& out)
    {out << "FULL-OK-END" << endl;}
};
template <class T, class... TS>
struct FULL<T, TS...>{
    static void test(std::ostream& out)
    {
        out << "FULL-OK" << endl;
        FULL<TS...>::test(out);
    }
};
template <typename T>
struct B{};
int main()
{
    FULL<int, int, int>::test(cout);
    PARTIAL<B, B, B>::test(cout);
    return 0;
}

The output of GCC5.3 (MINGW):

FULL-OK
FULL-OK
FULL-OK-END
PARTIAL-OK
PARTIAL-OK
PARTIAL-OK-END

The output of MSVC:

FULL-OK
FULL-OK
FULL-OK-END
PARTIAL-OK
PARTIAL-OK
PARTIAL-OK
PARTIAL-PROBLEM

MSVC produces code different way for full defined types and partials. What should be the best workaround of this?

here is demo that works good on GCC


向递归案例添加另一个参数将确保它未被选中用于终止案例:

template <template<typename> class T, template<typename> class T2, template<typename> class... TS>
//                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
struct PARTIAL<T, T2, TS...>{
//                ^^^^
    static void test(std::ostream& out)
    {
        out << "PARTIAL-OK" << endl;
        PARTIAL<T2, TS...>::test(out);
                ^^^^
    }
};
链接地址: http://www.djcxy.com/p/92348.html

上一篇: 从N出现开始返回子字符串

下一篇: MSVC2015更新3可变模板解决方法