3

Under C++ concepts: Allocator

would like some clarity on the following:

A::template rebind::other (optional1)

Notes: 1 rebind is only optional (provided by std::allocator_traits) if this allocator is a template of the form SomeAllocator<T, Args>, where Args is zero or more additional template parameters.

Why would rebind be optional in the above case?

Jarod42
  • 203,559
  • 14
  • 181
  • 302
user9196120
  • 381
  • 3
  • 9
  • 1
    It is "generated" in that case (to be `SomeAllocator`). – Jarod42 May 10 '18 at 02:58
  • Related: https://stackoverflow.com/questions/14148756/what-does-template-rebind-do and https://stackoverflow.com/questions/12362363/why-is-allocatorrebind-necessary-when-we-have-template-template-parameters – Jerry Jeremiah May 10 '18 at 03:06

1 Answers1

1

The standard library always accesses Allocators through the std::allocator_traits template. This template provides a default definition of rebind if it conforms to the form Alloc<U, Args>

rebind_alloc<T> Alloc::rebind<T>::other if present, otherwise Alloc<T, Args> if this Alloc is Alloc<U, Args> - cppreference.com : std::allocator_traits

andypea
  • 1,343
  • 11
  • 22