After reading a very in-depth article on fancy pointers, where it is also described their correlation with allocators, I had a doubt. The paper covers several aspects of fancy pointers, but does not specify whether two different specializations of a FancyPtr type require to have the same difference_type.
By extension, I have the following question: given an allocator A and two different specializations, std::allocator_traits<A>::rebind_alloc<T> and std::allocator_traits<A>::rebind_alloc<U>, are size_type and difference_type guaranteed to be the same?
The C++ Standard Library provides the concept of allocators for memory management. The
rebindmechanism is used to convert an allocator for one type to an allocator for another type, ensuring that the allocator'stypedefmembers likesize_typeanddifference_typeare adapted to the new type.In most cases, when you use
rebindto adapt an allocator to a different type, thesize_typeanddifference_typeof the rebound allocator will remain the same as the original allocator. This is because these typedefs are often dependent on the allocator itself, rather than the types it allocates.However, the C++ standard doesn't mandate that
size_typeanddifference_typemust be the same across all allocator specializations, even after rebinding. It's not guaranteed behavior. While it's common forsize_typeanddifference_typeto remain the same after rebinding, there might be specific scenarios or custom allocators where these types could differ.If you want to ensure the behavior for a specific allocator or fancy pointer, you should refer to the documentation for that particular allocator or pointer type. Always rely on the documentation and specifications provided by the library or framework you are using, as there could be implementation-specific differences or variations.