c++ - When do Allocator::pointer and Allocator::value_type* differ? -


i have doubt regarding question, in particular this answer.
there part is left exercise reader (it not problem itself), in particular jonathan wakely (the author of answer) said that:

this code asserts allocator::pointer allocator::value_type*

that expressed in code as:

static_assert(std::is_same<typename at::pointer, typename at::value_type*>::value, "allocator doesn't use fancy pointers"); 

at time, got answer , that's all.
when reading again after while, found myself asking aloud: fancy pointers?
here (documentation of allocator_traits), pointer defined as:

alloc::pointer if present, otherwise value_type*

the question arose: what's realistic case in allocator::pointer , allocator::value_type* differ?

the requirements allocator laid out in [allocator.requirements]. allocator class x type t, relevant requirements see are:

  • x::pointer convertible x::const_pointer
  • *p has type t&, p of type x::pointer
  • *q has type t const& q of type x::const_pointer
  • p->m has type t::m (conditioned on (*p).m being well-defined)
  • q->m has type t::m (conditioned on (*q).m being well-defined)

all of requirements satisfed pointer being shared_ptr<t>. in case, pointer not same value_type* (which t*).


Comments