Purpose of rebind in the following container

  allocator, c++, c++17

I am reading some C++ code and specifically trying to understand a customised container.

The container has following the template parameters:

 template<typename T, typename Alloc>
 class container{ ... };

Where T is the type of data like float or int. The Alloc is the allocator and could be one of the standard libraries ones.

Within that container I find following:

 class Container{ ....
 template<typename NewType> 
  struct Rebind
   { 
      using newalloc = typename std::allocator_traits<Alloc>::template rebind_alloc<NewType>; 
      using Other    =       container<NewType, newalloc>
   }
 }

I dont find anywhere the struct member of Rebind used explicitly at least and I am struggling to understand the purpose of it.

What is the developer trying to achieve by having the struct within the container?

Source: Windows Questions C++

LEAVE A COMMENT