Template Template Template in VS2015

I ran into a curious problem. Given the template class and template function:

template<typename L, typename T>
class TemplateClass
{
public:

   int operator()()
   {
      return 1;
   }
};

template<typename K, template<typename L, 
                              typename T = int> class TemplateCl>
TemplateCl<K> getTemplateClass(TemplateCl<K> _cls)
{
   TemplateCl<K> cls;
   return cls;
}

int main()
{
    auto templateClass = TemplateClass<int,int>();
    auto rTemplateClass = getTemplateClass<int>(templateClass);
    return 0;
}

      

This code is compiled by Clang, but when I try to compile with VS2015 it fails:

Severity    Code    Description Project File    Line    Suppression State
Error   C2672   'getTemplateClass': no matching overloaded function found   cpp11_cpp14_cpp17   d:\projects_programing\__testing\cpp11_cpp14_cpp17\cpp11_cpp14_cpp17\cpp11_cpp14_cpp17.cpp  682 
Severity    Code    Description Project File    Line    Suppression State
Error   C2893   Failed to specialize function template 'TemplateCl<K,int> getTemplateClass(TemplateCl<K,int>)'  cpp11_cpp14_cpp17   d:\projects_programing\__testing\cpp11_cpp14_cpp17\cpp11_cpp14_cpp17\cpp11_cpp14_cpp17.cpp  682 

      

This code only compiles with the following changes:

template<typename L, typename T = int>
class TemplateClass
{
public:

   int operator()()
   {
      return 1;
   }
};

      

The strangest situation is when it even compiles with the following modification:

template<typename L, typename T = float>
class TemplateClass
{
public:

   int operator()()
   {
      return 1;
   }
};

      

Is this a problem in the VS2015 compiler? Does anyone know why VS2015 has this behavior?

+3
c ++ templates visual-studio-2015 template-templates


source to share


No one has answered this question yet

Check out similar questions:

1643
Why templates can only be implemented in a header file?
961
Where and why do I need to put the keywords "pattern" and "name-type"?
563
Use 'class' or 'typename' for template parameters?
480
Does the C ++ standard allow uninitialized bool to crash?
366
Pretty printable STL STL containers
217
What are some of the template template options?
23
Nested template classes with a pointer to a method not compiled in clang ++
2
Copy ctor not working as expected in VS2015
2
Template functor with any parameters
0
C ++ Variadic template for evaluating pointer to member



All Articles
Loading...
X
Show
Funny
Dev
Pics