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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:53:13+00:00 2026-05-28T01:53:13+00:00

In the code below, when the signified code is commented out, code works as

  • 0

In the code below, when the signified code is commented out, code works as expected – Type matches the (first) template argument.

However, if I uncomment it, Type becomes char instead of std::string. This is the same with both MSVC and GCC. So it works when I have specialization of StripTag for a tag template with one and two arguments, but when I specialize it in exactly the same way for three arguments, I get this strange behavior.

Anyone has any ideas?

Code follows:

#include <typeinfo>
#include <stdio.h>
#include <string>

template <typename T>
struct StripTag
{typedef T Type;};

template<typename T, template<typename T> class Tag >
struct StripTag<Tag<T> >
{ typedef typename StripTag<T>::Type Type; };

template<typename T, typename X, template<typename T, typename X> class Tag >
struct StripTag<Tag<T,X> >
{ typedef typename StripTag<T>::Type Type; };

/*
//UNCOMMENT THIS AND RECOMPILE
template<typename T, typename X, typename Y, template<typename T, typename X, typename Y> class Tag >
struct StripTag<Tag<T,X,Y> >
{ typedef typename StripTag<T>::Type Type; };
*/

template <class C>
struct Test
{
typedef C Type;
};

template <typename A, typename B>
struct Blah{};

int main()
{

    printf("typeid of StripTag=\t%s\n", typeid(StripTag<std::string>::Type).name());
    printf("typeid of StripTag2=\t%s\n", typeid(StripTag<Blah<std::string, bool> >::Type).name());
    printf("typeid of Test=\t\t%s\n", typeid(Test<std::string>::Type).name());
    printf("typeid of std::string=\t%s\n", typeid(std::string).name());
}
  • 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-28T01:53:14+00:00Added an answer on May 28, 2026 at 1:53 am

    This is because std::string is really just a typedef for

    std::basic_string<char, std::char_traits<char>, std::allocator<char>>
    

    This, as you can see, is a class template with three type parameters.

    When you have a StripTag specialization that takes a three-parameter class template as one of its parameters, that specialization is a better match for std::string than the primary class template (because it is more specific).

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

Sidebar

Related Questions

The code below works. But if I comment out the line Dim objRequest As
Code below is not working as expected to detect if it is in design
The code below gives an error: Property 'Int32 Key' is not defined for type
The code below is the code i am using. It works fine in thunderbird
The code below continues many lines until it ends with a expected /veotherwise /vechoose.
Code below defines a ChargeCustomer class that contains an array of type customers. I
The code below works, but I suspect there is be a cleaner. Any alternative
My code below kinda works, it creates the User object and saves but it
code below for a simple auto suggest box... however when I click a suggestion
The code below works great. It creates a list of words occurring in the

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.