I found this strange while I was reading this. It says value_type
equals to T
, but construct()
constructs an object of type X
, which has nothing to do with T
.
However, reference page of std::vector only says
An allocator that is used to acquire/release memory and to construct/destroy the elements in that memory. The type must meet the requirements of Allocator. The behavior is undefined (until C++20)The program is ill-formed (since C++20) if Allocator::value_type is not the same as T.
so I thought that this means I can use any Allocator
for std::vector<T, Allocator>
if Allocator
meets the requirements of Allocator and Allocator::value_type
is same as T
.
But if what Allocator::construct()
really constructs is not Allocator::value_type
, how can std::vector
's implementation constructs the element of std::vector
?
Edit: Well, std::vector
's implementation can just use 'placement new', but then what is this Allocator::construct()
all about? If it is not meant to be used in such situations like constructing elements of STL containers, in what kinds of situation is it really meant to be used?