Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards


Struct template pointer_plus_bits<T *, NumBits>

boost::intrusive::pointer_plus_bits<T *, NumBits>


// In header: <boost/intrusive/pointer_plus_bits.hpp>

template<typename T, std::size_t NumBits> 
struct pointer_plus_bits<T *, NumBits> {
  // types
  typedef T * pointer;

  // public static functions
  static pointer get_pointer(pointer) noexcept;
  static void set_pointer(pointer &, pointer) noexcept;
  static std::size_t get_bits(pointer) noexcept;
  static void set_bits(pointer &, std::size_t) noexcept;

  // public data members
  static const uintptr_t Mask;


This is the specialization to embed extra bits of information in a raw pointer. The extra bits are stored in the lower bits of the pointer.

pointer_plus_bits public static functions

  1. static pointer get_pointer(pointer n) noexcept;
  2. static void set_pointer(pointer & n, pointer p) noexcept;
  3. static std::size_t get_bits(pointer n) noexcept;
  4. static void set_bits(pointer & n, std::size_t c) noexcept;