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

  • Home
  • SEARCH
  • 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 246623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:11:17+00:00 2026-05-11T21:11:17+00:00

According to this article from Herb Sutter, one should always pick Class Specializing over

  • 0

According to this article from Herb Sutter, one should always pick Class Specializing over Function Overload and definitely over Specialized Function Templates.

The reason is that

  • Specializations don’t overload. Overload resolution only selects a base template (or a nontemplate function, if one is available). Only after it’s been decided which base template is going to be selected, and that choice is locked in, will the compiler look around to see if there happens to be a suitable specialization of that template available, and if so that specialization will get used.
  • we can’t particial specialize function templates.

I must admit that before I read the article I have banged my head against the wall a few times. Why isn’t he picking my specialized function …
After reading the article I’ve never used Specialized Function Templates again.

Example:

template <class T> void foo( T t);

We should write foo like this so we can specialize it with class templates instead of function specializing.

template<class T> 
struct FooImpl;

template <class T> void foo( T t) {
    FooImpl<T>::foo(t);
}

Now we can specialze the template and don’t have to worry about the overload rules and we can even partitial specialize the template like this:

template<class U, class V> 
struct FooImpl< QMap< U, V > >;

Here is the question.

It seems that the StackOverflow members prefer Specialized Function Templates?
Why?
Because the Specialized Function Templates get a lot more upvotes than the Overload Solutions and the Class Specializing.
With the information that i have at the moment i find it perverse because i know that i can get it right, but i know that the one who comes after me will hit the wall.

There are already some links to the GOTWCA article so you must have read the article. This means that upvoters must have some extra information, please stand up and enlighten me.

  • 1 1 Answer
  • 2 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-11T21:11:17+00:00Added an answer on May 11, 2026 at 9:11 pm

    The problem with explicitly specialising a function template only applies if the function is also overloaded:

    template <typename T> void foo (T*);   // #1
    
    template <typename T> void foo (T);    // #2
    template <> void foo<int*> (int*);
    
    int main () {
      int * i;
      foo (i);  // Calls #1 not specialization of #2
    }
    

    Without the #1 overload, the code will work as expected. However, a function that starts out not being overloaded may have overloads added as the code is maintained into the future.

    This is one of those examples where, although I hate to say it, C++ has too many ways to do the same thing. Personally, if you find you need to specialise a function template, then I like the pattern suggested by TimW in his comment against Neil Butterworth’s answer, ie. it’s best to do so by having the current function dispatch it’s call to a specialized class template instead:

    template <typename T> class DoFoo {
        static void do (T) { /* default behaviour */ }
    };
    template <> class DoFoo<int*> {
        static void do (int*) { /* int * behaviour */ }
    };
    
    template <typename T> void foo (T t)
    {
      DoFoo<T>::do (t);
    }
    

    If ‘foo’ is overloaded, then at least it’s clearer to the developer that this function won’t be called, ie. the developer doesn’t need to be a standards guru to know how the specialization rules interact with overload resolution.

    Ultimately, however, the code generated by the compiler is going to be the same, this is purely a code comprehension issue on the part of the developer.

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

Sidebar

Ask A Question

Stats

  • Questions 199k
  • Answers 199k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are almost correct, but not quite. In… May 12, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer I don't see any particular problem. You would have to… May 12, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer A ListView with the view propterty set to "Details" possibly. May 12, 2026 at 7:46 pm

Related Questions

I have a WinForms .NET app that, according to the Vista Task Manager with
According to this article Silverlight 2 Beta 2 supports the DataContractJsonSerializer object. But, when
I'm using pyDes to encrypt some data. I wanted to demonstrate that if you
I will choose Java as an example, most people know it, though every other

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.