...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::interprocess::offset_ptr
// In header: <boost/interprocess/interprocess_fwd.hpp> template<typename T, typename DifferenceType = std::ptrdiff_t, typename OffsetType = std::size_t, std::size_t Alignment = offset_type_alignment> class offset_ptr { public: // construct/copy/destruct offset_ptr(); offset_ptr(pointer); template<typename T> offset_ptr(T *, unspecified = 0); offset_ptr(const offset_ptr &); template<typename T2> offset_ptr(const offset_ptr< T2, DifferenceType, OffsetType, OffsetAlignment > &); template<typename T2, typename P2, typename O2, std::size_t A2> offset_ptr(const offset_ptr< T2, P2, O2, A2 > &, unspecified); template<typename T2, typename P2, typename O2, std::size_t A2> offset_ptr(const offset_ptr< T2, P2, O2, A2 > &, unspecified); template<typename T2, typename P2, typename O2, std::size_t A2> offset_ptr(const offset_ptr< T2, P2, O2, A2 > &, unspecified); template<typename T2, typename P2, typename O2, std::size_t A2> offset_ptr(const offset_ptr< T2, P2, O2, A2 > &, unspecified); offset_ptr& operator=(pointer); offset_ptr& operator=(const offset_ptr &); template<typename T2> offset_ptr& operator=(const offset_ptr< T2, DifferenceType, OffsetType, OffsetAlignment > &); // public member functions pointer get() const; offset_type get_offset() const; pointer operator->() const; reference operator*() const; reference operator[](difference_type) const; offset_ptr & operator+=(difference_type); offset_ptr & operator-=(difference_type); offset_ptr & operator++(void); offset_ptr operator++(int); offset_ptr & operator--(void); offset_ptr operator--(int); operator unspecified_bool_type() const; bool operator!() const; // public static functions static offset_ptr pointer_to(reference); // friend functions friend offset_ptr operator+(difference_type, offset_ptr); friend offset_ptr operator+(offset_ptr, difference_type); friend offset_ptr operator-(offset_ptr, difference_type); friend offset_ptr operator-(difference_type, offset_ptr); friend difference_type operator-(const offset_ptr &, const offset_ptr &); };
A smart pointer that stores the offset between between the pointer and the the object it points. This allows offset allows special properties, since the pointer is independent from the address address of the pointee, if the pointer and the pointee are still separated by the same offset. This feature converts offset_ptr in a smart pointer that can be placed in shared memory and memory mapped files mapped in different addresses in every process.
offset_ptr
public
construct/copy/destructoffset_ptr();
Default constructor (null pointer). Never throws.
offset_ptr(pointer ptr);
Constructor from raw pointer (allows "0" pointer conversion). Never throws.
template<typename T> offset_ptr(T * ptr, unspecified = 0);
Constructor from other pointer. Never throws.
offset_ptr(const offset_ptr & ptr);
Constructor from other offset_ptr
Never throws.
template<typename T2> offset_ptr(const offset_ptr< T2, DifferenceType, OffsetType, OffsetAlignment > & ptr);
Constructor from other offset_ptr
. If pointers of pointee types are convertible, offset_ptrs will be convertibles. Never throws.
template<typename T2, typename P2, typename O2, std::size_t A2> offset_ptr(const offset_ptr< T2, P2, O2, A2 > & r, unspecified);
Emulates static_cast operator. Never throws.
template<typename T2, typename P2, typename O2, std::size_t A2> offset_ptr(const offset_ptr< T2, P2, O2, A2 > & r, unspecified);
Emulates const_cast operator. Never throws.
template<typename T2, typename P2, typename O2, std::size_t A2> offset_ptr(const offset_ptr< T2, P2, O2, A2 > & r, unspecified);
Emulates dynamic_cast operator. Never throws.
template<typename T2, typename P2, typename O2, std::size_t A2> offset_ptr(const offset_ptr< T2, P2, O2, A2 > & r, unspecified);
Emulates reinterpret_cast operator. Never throws.
offset_ptr& operator=(pointer from);
Assignment from pointer (saves extra conversion). Never throws.
offset_ptr& operator=(const offset_ptr & ptr);
Assignment from other offset_ptr
. Never throws.
template<typename T2> offset_ptr& operator=(const offset_ptr< T2, DifferenceType, OffsetType, OffsetAlignment > & ptr);
Assignment from related offset_ptr
. If pointers of pointee types are assignable, offset_ptrs will be assignable. Never throws.
offset_ptr
public member functionspointer get() const;
Obtains raw pointer from offset. Never throws.
offset_type get_offset() const;
pointer operator->() const;
Pointer-like -> operator. It can return 0 pointer. Never throws.
reference operator*() const;
Dereferencing operator, if it is a null offset_ptr
behavior is undefined. Never throws.
reference operator[](difference_type idx) const;
Indexing operator. Never throws.
offset_ptr & operator+=(difference_type offset);
offset_ptr
+= difference_type. Never throws.
offset_ptr & operator-=(difference_type offset);
offset_ptr
-= difference_type. Never throws.
offset_ptr & operator++(void);
++offset_ptr. Never throws.
offset_ptr operator++(int);
offset_ptr++. Never throws.
offset_ptr & operator--(void);
<ndash></ndash>offset_ptr
. Never throws.
offset_ptr operator--(int);
offset_ptr
<ndash></ndash>. Never throws.
operator unspecified_bool_type() const;
safe bool conversion operator. Never throws.
bool operator!() const;
Not operator. Not needed in theory, but improves portability. Never throws
offset_ptr
public static functionsstatic offset_ptr pointer_to(reference r);
Compatibility with pointer_traits
offset_ptr
friend functionsfriend offset_ptr operator+(difference_type diff, offset_ptr right);
difference_type + offset_ptr
operation
friend offset_ptr operator+(offset_ptr left, difference_type diff);
offset_ptr
+ difference_type operation
friend offset_ptr operator-(offset_ptr left, difference_type diff);
offset_ptr
- diff operation
friend offset_ptr operator-(difference_type diff, offset_ptr right);
offset_ptr
- diff operation
friend difference_type operator-(const offset_ptr & pt, const offset_ptr & pt2);
offset_ptr
- offset_ptr
operation