Why is allocator::rebind necessary when we have template template parameters?

A quoted text from Foundations of Algorithms in C++11, Volume 1, chap 4, p. 35 :

template <typename T> 
struct allocator 
{  
   template <typename U>  
   using  rebind = allocator<U>; 
}; 

sample usage :

allocator<int>::rebind<char> x;

In The C++ Programming Language, 4th edition, section 34.4.1, p. 998, commenting the ‘classical’ rebind member in default allocator class :

template<typename U>
     struct rebind { using other = allocator<U>;};

Bjarne Stroustrup writes this:

The curious rebind template is an archaic alias. It should have been:

template<typename U>
using other = allocator<U>;

However, allocator was defined before such aliases were supported by C++.

Leave a Comment