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 8108887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:14:59+00:00 2026-06-06T01:14:59+00:00

What is the procedure of comparing the class template specializations? The standard is not

  • 0

What is the procedure of comparing the class template specializations? The standard is not detailed on this point (or I am missing the right place).
My question has NOTHING TO DO with deciding what specialization to use during the instantiation. Please, do not comment on that. The question is about comparing the specializations with each other to decide if particular specialization is already defined or not yet.

Consider this sample code:

template <class x1, class x2>
struct CoreTemplate { };

template <class x1, class x2>
struct CoreTemplate<x1*, x2*> { int spec; CoreTemplate() { spec = 1; } };

template <class x1, class x2>
struct CoreTemplate<x2*, x1*> { int spec; CoreTemplate() { spec = 2; } };

int main(int argc, char* argv[])
{
    CoreTemplate<int*, int*> qq;
    printf("var=%d.\r\n", qq.spec);
}

When I try to compile this code with MSVC, I get an error for the instantiation attempt inside the main function:

cpptest1.cxx(15) : error C2752: ‘CoreTemplate<x1,x2>‘ : more than one partial specialization matches the template argument list

For me it would be more logical to issue an error for an attempt to declare identical template specializations. I do not see any difference between the specializations above.

So, does anybody know rules of comparing template specializations? Articles, links, books, etc will also help.

  • 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-06-06T01:15:02+00:00Added an answer on June 6, 2026 at 1:15 am

    The standard is specific in stating that this only happens when you attempt to instantiate the template (§14.5.4.1/1):

    When a class template is used in a context that requires an instantiation of the class, it is necessary to determine whether the instantiation is to be generated using the primary template or one of the partial specializations. [emphasis added]

    Unfortunately, the rest of your question can’t be answered without discussing how to decide which specialization to use during instantiation. Here’s the text from the standard (continuing from the excerpt above):

    This is done by matching the template arguments of the class template specialization with the template argument lists of the partial specializations.

    • If exactly one matching specialization is found, the instantiation is generated from that specialization.
    • If more than one matching specialization is found, the partial order rules (14.5.4.2) are used to determine whether one of the specializations is more specialized than the others. If none of the specializations is more specialized than all of the other matching specializations, then the use of the class template is ambiguous and the program is ill-formed.

    So, it never even attempts to compare the templates directly to each other at all. Rather, it attempts to find a specialization that will match the arguments given. If more than one matches, it attempts to pick the most specialized one based on the partial ordering rules. If neither is more specialized than the other, then the instantiation is ambiguous, and compilation fails.

    Now, it’s certainly true that neither of these specializations could ever be used, since there would always be ambiguity — if either matches, the other obviously matches equally well. There’s simply no requirement for the compiler to detect or diagnose that though. In this exact case (essentially identical specializations) that would probably be easy, but there are almost certainly other cases where it would be much more difficult, so (apparently) the committee decided the compiler didn’t even have to try.

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

Sidebar

Related Questions

Please consider this simplified example: type TForm43 = class(TForm) drwgrd1: TDrawGrid; procedure drwgrd1DrawCell(Sender: TObject;
procedure MyProc(Eval: Boolean); begin if not Eval then Exit; /* do stuff */ /*
My procedure for using log4j is this: put a .properties file somewhere in a
This is part observation, part question. First the observation: While everyone talks of modular
I'm using ode45() in matlab for some work in dynamics, using this procedure to
I'm trying to compile this stored procedure on MSSQL: ALTER PROCEDURE [dbo].[sp_Notice_insert] @type text,
I'm having a problem with a stored procedure. It's comparing a new record with
I have a question about inserting column stored procedure into table. I have two
I'm comparing some classifiers. My procedure is to compute the confusion matrix with the
Oracle SP not compiling I am expierenced at MS SQL but taking a class

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.