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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:41:39+00:00 2026-05-23T06:41:39+00:00

I have the following code: template<typename T, typename Allocator = std::allocator<T> > class Carray

  • 0

I have the following code:

template<typename T, typename Allocator = std::allocator<T> >
class Carray {
    // ...
    typedef T* pointer;
    typedef pointer iterator;
    // ...
};

Now I’m trying to do partial specialization for iterator_traits. It seems OK to me, but g++ 4.4.5 complains:

#include <iterator>

namespace std {
    template<typename T, typename Allocator>
    struct iterator_traits<typename Carray<T, Allocator>::iterator> { // line 128
        typedef T value_type;
        typedef typename Allocator::difference_type difference_type;
        typedef typename Allocator::reference reference;
        typedef typename Allocator::pointer pointer;
        typedef typename std::random_access_iterator_tag iterator_category;
    };
}

This is the full error message:

carray.h:128: error: template parameters not used in partial specialization:
carray.h:128: error:         ‘T’
carray.h:130: error: ‘Allocator’ has not been declared
carray.h:131: error: ‘Allocator’ has not been declared
carray.h:132: error: ‘Allocator’ has not been declared
  • 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-23T06:41:40+00:00Added an answer on May 23, 2026 at 6:41 am

    You shouldn’t need a specialization at all here: iterator_traits is already specialized for pointer types and if you do end up with an iterator that is a class type, you can just define those required typedefs in the iterator class.

    The problem is that in order to match the primary specialization, the compiler needs to take the arguments with which the template is used, plug them into the specialization, and see whether they match.

    Consider what would happen in the following simplified scenario:

    template <typename T> struct S { typedef int type; };
    
    template <typename T> 
    struct Traits { };
    
    template <typename T> 
    struct Traits<typename S<T>::type> { };
    

    How is the compiler supposed to know what T to plug into S or whether some S<T>::type is really meant instead of just int?

    The problem is that the nested typedef (::type) depends on the template parameter (T). When this is the case in a function argument list or in a partial specialization, the type T cannot be deduced (it is a “non-deduced context”).

    • 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: class TimeOutException {}; template <typename T> class MultiThreadedBuffer {
I have the following code: template <class T> struct pointer { operator pointer<const T>()
I have the following code: template <typename Provider> inline void use() { typedef Provider::Data<int>
I have the following code fragment: template <class T> struct ServicePtr { std::shared_ptr<T> service;
I have the following small code: template <typename T> class V { public: T
I have the following code, which does some iterator arithmetic: template<class Iterator> void Foo(Iterator
I have a problem with the following code: template <typename U> class lamePtr {
let's say I have the following code in A.cpp file: template <typename T> class
I have the following code: typedef vector<int> Vec; typedef vector<Vec> VecOfVec; template<typename Vec> Vec
I have the following code: template <typename T> LuaCall& operator>>(T) { BOOST_STATIC_ASSERT(sizeof(T) == 0);

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.