Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a fancy pointer look like?

Tags:

c++

pointers

The C++ reference mentions a concept called fancy pointers. I learned about their existence from a recent heavily down-voted and afterwards deleted question.

The definition is rater vague:

When the member type pointer is not a raw pointer type, it is commonly referred to as a "fancy pointer".

Their use case example is:

An example of a fancy pointer is the mapping address-independent pointer boost::interprocess::offset_ptr, which makes it possible to allocate node-based data structures such as std::set in shared memory and memory mapped files mapped in different addresses in every process. Fancy pointers can be used independently of the allocator that provided them, through the class template std::pointer_traits.

I don't understand that explanation. What is the syntax for creating a fancy pointer and why can't I use a regular pointer in this case?

like image 857
Beginner Avatar asked Apr 18 '17 12:04

Beginner


1 Answers

A fancy pointer is just a term for something that acts like a pointer but is not. Take, for example, an iterator. Pretty much all iterators are custom class types, but they behave just like a pointer (sometimes there are restrictions and you cannot do all the operations supported by a pointer as they do not provide random access but that is part of the fanciness.)

To put it another way: An abstraction that acts like a pointer is a fancy pointer.

like image 113
NathanOliver Avatar answered Oct 27 '22 20:10

NathanOliver