Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7680331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:05:27+00:00 2026-05-31T18:05:27+00:00

I have code: #include <cstdio> template<template<typename…> class> struct Foo { enum { n =

  • 0

I have code:

#include <cstdio>

template<template<typename...> class>
struct Foo 
{ 
    enum { n = 77 };
};

template<template<typename, typename...> class C>
struct Foo<C>
{
    enum { n = 99 }; 
};

template<typename...> struct A { };

template<typename, typename...> struct B { };

int main(int, char**)
{
    printf("%d\n", Foo<A>::n);
    printf("%d\n", Foo<B>::n);
}

The idea is that template<typename, typename...> class is a subset of template<typename...> class, so it might be possible to specialize on it. But it’s pretty esoteric, so maybe not. Let’s try it out.

GCC 4.7 says:

$ g++ -std=c++11 test157.cpp 

It compiled!

Running it:

$ ./a.out 
77
99

It works!

Clang 3.1 says:

$ clang++ -std=c++11 test157.cpp
test157.cpp:10:8: error: class template partial specialization does not specialize any template argument; to define the primary template, remove the template argument list
struct Foo<C>
       ^  ~~~
test157.cpp:9:10: error: too many template parameters in template template parameter redeclaration
template<template<typename, typename...> class C>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test157.cpp:3:10: note: previous template template parameter is here
template<template<typename...> class>
         ^~~~~~~~~~~~~~~~~~~~~
2 errors generated.

Who’s right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:05:28+00:00Added an answer on May 31, 2026 at 6:05 pm

    Clang is wrong to reject the partial specialization. To know how to interpret the errormessage, you need to understand what clang diagnoses. It means to diagnose a partial specialization whose arguments match exactly the implicit argument list of the primary class template (<param1, param2, ... , paramN>).

    However the argument lists are differently so clang shall not diagnose it. In particular this has nothing to do wheter the partial specialization matches more or less arguments. Consider

    template<typename A, typename B> class C;
    template<typename B, typename A> class C<A, B> {};
    

    The partial specialization here matches everything and not more that the primary template would match. And the argument lists of both templates are different so this partial specialization is valid, just like you’rs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: #include <cstdio> template<class Fun, class... Args> void foo(Fun f,
I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
I have the following code: #include <boost/shared_ptr.hpp> struct Foo { int a; }; static
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this code: #include <iostream> class foo { public: foo(int yy){y = yy;}
I have some C++ code #include <cstdio> #include <boost/bind.hpp> #include <boost/function.hpp> class A {
I have this code: #include <iostream> #include <functional> struct A { int operator()(int i)
i have the following code: #include <stdio.h> int main(void) { float a[4] __attribute__((aligned(0x1000))) =
I have this code #include <iostream> using namespace std; class Test{ public: int a;
Here is my code: 1 #include <cstdio> 2 3 struct Foo; 4 5 struct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.