I have a doubt regarding a question, in particular about this answer.
There is a part that is left as an exercise for the reader (it is not a problem for itself), in particular Jonathan Wakely (the author of the answer) said that:
This code asserts that Allocator::pointer is Allocator::value_type*
That is expressed in code as:
static_assert(std::is_same<typename AT::pointer, typename AT::value_type*>::value, "Allocator doesn't use fancy pointers");
At the time, I got the answer as is and that's all.
When I was reading it again after a while, I found myself asking aloud: fancy pointers?
From here (documentation of allocator_traits), pointer is defined as:
Alloc::pointer if present, otherwise value_type*
The question thus arose: what's a realistic case in which Allocator::pointer and Allocator::value_type* actually differ?
One thing that comes to mind is something that might have been realistic when the allocator spec was written.
A very long time ago, there were different types of pointers in the Intel Segmented Memory Model: near, far, and huge, displaying speed/size tradeoffs.
Nowadays, with the current virtual memory architecture, they don't have any real use, anymore. In the old setting, though, conceptually an allocator could typedef:
typdef T *huge pointer;
and it would carry more information than just T *.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With