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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:07:41+00:00 2026-06-12T07:07:41+00:00

I’ve got some code that compiles fine under MSVC (or so say the Windows

  • 0

I’ve got some code that compiles fine under MSVC (or so say the Windows developers who sent me it), but gives an error under CLang. Having looked around I’ve found that CLang is indeed more strict about resolving template specializations, but I’m not sure where I should put the specializations in my case. Basically one of my files has a struct like this:

template<>
struct iterator_traits< char * >   // error is here
{
    typedef random_access_iterator_tag iterator_category;
    typedef char value_type;
    typedef ptrdiff_t difference_type;
    typedef difference_type distance_type;
    typedef char * pointer;
    typedef char & reference;
};

This is within a namespace std block. The error message is:

Explicit specialization of 'std::iterator_traits<char *>' after instantiation

Another part of the same error message (viewed by ‘expanding’ the error message in Xcode) says Implicit instantiation first required here, and clicking on that takes me to stl_iterator.h, specifically this line (line 642):

typedef typename iterator_traits<_Iterator>::iterator_category
                                                         iterator_category;

Does anyone know what the correct thing to do would be in this case? I’ve seen examples involving classes but never one involving a struct.

  • 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-12T07:07:42+00:00Added an answer on June 12, 2026 at 7:07 am

    The compiler is complaining that you’re trying to specialize a template after instantiating the generic template — by that point in time, the compiler has already used the generic template for the instantiation, and it can’t go back and use your specialization instead. In other words, something like this:

    template <typename T>
    struct X
    {
        // Generic implementation
    };
    
    // Instantiate template by using it in any way
    X<int> foo;
    
    template<>
    struct X<int>
    {
        // Specialization implementation for int
    };
    

    The fix is to define the specialization before it’s instantiated, so in this example, you’d move the X<int> specialization to before where X<int> is used.

    Note that the STL already defines specializations of std::iterator_trait for pointer types, so there’s no need to define your own specialization here for char*. You’d typically only do that for user-defined iterator types which are not pointers. See §24.3.1/2 of the C++03 standard:

    [The template iterator_traits<Iterator>] is specialized for pointers as

    template<class T> struct iterator_traits<T*> {
      typedef ptrdiff_t difference_type;
      typedef T value_type;
      typedef T* pointer;
      typedef T& reference;
      typedef random_access_iterator_tag iterator_category;
    };
    

    and for pointers to const as

    template<class T> struct iterator_traits<const T*> {
      typedef ptrdiff_t difference_type;
      typedef T value_type;
      typedef const T* pointer;
      typedef const T& reference;
      typedef random_access_iterator_tag iterator_category;
    };
    

    So there’s no point to providing your own std::iterator_traits<char*> specialization. Since char* is not a user-defined type, it’s also undefined behavior according to the standard. §17.4.3.1/1 says:

    It is undefined for a C + + program to add declarations or definitions to namespace std or namespaces
    within namespace std unless otherwise specified. A program may add template specializations for any
    standard library template to namespace std. Such a specialization (complete or partial) of a standard
    library template results in undefined behavior unless the declaration depends on a user-defined name of
    external linkage and unless the specialization meets the standard library requirements for the original template.163)

    163) Any library code that instantiates other library templates must be prepared to work adequately with any user-supplied specialization
    that meets the minimum requirements of the Standard

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.