Related: Why do standard containers require allocator_type::value_type to be the element type?
It is said that the following has been deprecated since C++17:
template<>
struct allocator<void>;
I wonder whether it is deprecated because the primary template alone is now able to accommodate allocator<void>
, or the use-case of allocator<void>
is deprecated.
If latter, I wonder why. I think allocator<void>
is useful in specifying an allocator not bound to a specific type (so just some schema/metadata).
It's not that
std::allocator<void>
is deprecated, just it isn't a explicit specialisation.What it used to look like was something like:
Now, since
std::allocator<T>::reference
andstd::allocator<T>::const_reference
have been deprecated, there doesn't need to be an explicit specialisation forvoid
. You can just usestd::allocator<void>
, along withstd::allocator_traits<std::allocator<void>>::template rebind<U>
to getstd::allocator<U>
, you just can't instantiatestd::allocator<void>::allocates
.For example:
According to p0174r0