Update MSVC2015 3 Template Change Options

The Visual Studio 2015 3 update has significantly improved C ++ 11 support, but I have a strange problem and am looking for a workaround.

When compiling the variational pattern code with MSVC for the arguments of the pattern type ("fully defined types"), everything works well, but if I want to use the arguments of the pattern template ("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; } 

Output GCC5.3 (MINGW):

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

MSVC Output:

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

MSVC generates code differently for fully defined types and partitions. What should be the best workaround?

here is a demo that works well in gcc

+7
c ++ c ++ 11 visual-c ++ variadic-templates
source share
1 answer

Adding another parameter to the recursive case ensures that it will not be selected for the final case:

 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); ^^^^ } }; 
+4
source share

All Articles