xgboost

Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
xgboost::IntrusivePtr< T > Class Template Reference

Implementation of Intrusive Pointer. A smart pointer that points to an object with an embedded reference counter. The underlying object must implement a friend function IntrusivePtrRefCount() that returns the ref counter (of type IntrusivePtrCell). The intrusive pointer is faster than std::shared_ptr<>: std::shared_ptr<> makes an extra memory allocation for the ref counter whereas the intrusive pointer does not. More...

`#include <intrusive_ptr.h>`

Collaboration diagram for xgboost::IntrusivePtr< T >:

## Classes
struct | Hash

## Public Types
using | element_type = T

## Public Member Functions
| IntrusivePtr (T *p)
| Contruct an IntrusivePtr from raw pointer. IntrusivePtr takes the ownership. More...
| IntrusivePtr () noexcept=default
| IntrusivePtr (IntrusivePtr const &that)
| IntrusivePtr (IntrusivePtr &&that) noexcept
| ~IntrusivePtr ()
IntrusivePtr< T > & | operator= (IntrusivePtr< T > const &that)
IntrusivePtr< T > & | operator= (IntrusivePtr< T > &&that) noexcept
void | reset ()
void | reset (element_type *that)
element_type & | operator* () const noexcept
element_type * | operator-> () const noexcept
element_type * | get () const noexcept
| operator bool () const noexcept
int32_t | use_count () noexcept
void | swap (IntrusivePtr< T > &that) noexcept

## Protected Attributes
T * | ptr_ {nullptr}

## Detailed Description

### template<typename T>
class xgboost::IntrusivePtr< T >

Implementation of Intrusive Pointer. A smart pointer that points to an object with an embedded reference counter. The underlying object must implement a friend function IntrusivePtrRefCount() that returns the ref counter (of type IntrusivePtrCell). The intrusive pointer is faster than std::shared_ptr<>: std::shared_ptr<> makes an extra memory allocation for the ref counter whereas the intrusive pointer does not.

class ForIntrusivePtrTest {
public:
mutable class IntrusivePtrCell ref;
float data { 0 };
friend IntrusivePtrCell &
IntrusivePtrRefCount(ForIntrusivePtrTest const *t) noexcept { // NOLINT
return t->ref;
}
ForIntrusivePtrTest() = default;
ForIntrusivePtrTest(float a, int32_t b) : data{a + static_cast<float>(b)} {}
explicit ForIntrusivePtrTest(NotCopyConstructible a) : data{a.data} {}
};
IntrusivePtr<ForIntrusivePtrTest> ptr {new ForIntrusivePtrTest};

## Member Typedef Documentation

## ◆ element_type

template<typename T >

using xgboost::IntrusivePtr< T >::element_type = T

## Constructor & Destructor Documentation

## ◆ IntrusivePtr() [1/4]

template<typename T >

xgboost::IntrusivePtr< T >::IntrusivePtr | ( | T * | p | ) |
| inline explicit

Contruct an IntrusivePtr from raw pointer. IntrusivePtr takes the ownership.

Parameters

  p | Raw pointer to object

## ◆ IntrusivePtr() [2/4]

template<typename T >

xgboost::IntrusivePtr< T >::IntrusivePtr | ( |  | ) |
| default noexcept

## ◆ IntrusivePtr() [3/4]

template<typename T >

xgboost::IntrusivePtr< T >::IntrusivePtr | ( | IntrusivePtr< T > const & | that | ) |
| inline

## ◆ IntrusivePtr() [4/4]

template<typename T >

xgboost::IntrusivePtr< T >::IntrusivePtr | ( | IntrusivePtr< T > && | that | ) |
| inline noexcept

## ◆ ~IntrusivePtr()

template<typename T >

xgboost::IntrusivePtr< T >::~IntrusivePtr | ( |  | ) |
| inline

## Member Function Documentation

## ◆ get()

template<typename T >

element_type* xgboost::IntrusivePtr< T >::get | ( |  | ) | const
| inline noexcept

## ◆ operator bool()

template<typename T >

xgboost::IntrusivePtr< T >::operator bool | ( |  | ) | const
| inline explicit noexcept

## ◆ operator*()

template<typename T >

element_type& xgboost::IntrusivePtr< T >::operator* | ( |  | ) | const
| inline noexcept

## ◆ operator->()

template<typename T >

element_type* xgboost::IntrusivePtr< T >::operator-> | ( |  | ) | const
| inline noexcept

## ◆ operator=() [1/2]

template<typename T >

IntrusivePtr<T>& xgboost::IntrusivePtr< T >::operator= | ( | IntrusivePtr< T > && | that | ) |
| inline noexcept

## ◆ operator=() [2/2]

template<typename T >

IntrusivePtr<T>& xgboost::IntrusivePtr< T >::operator= | ( | IntrusivePtr< T > const & | that | ) |
| inline

## ◆ reset() [1/2]

template<typename T >

void xgboost::IntrusivePtr< T >::reset | ( |  | ) |
| inline

## ◆ reset() [2/2]

template<typename T >

void xgboost::IntrusivePtr< T >::reset | ( | element_type * | that | ) |
| inline

## ◆ swap()

template<typename T >

void xgboost::IntrusivePtr< T >::swap | ( | IntrusivePtr< T > & | that | ) |
| inline noexcept

## ◆ use_count()

template<typename T >

int32_t xgboost::IntrusivePtr< T >::use_count | ( |  | ) |
| inline noexcept

## Member Data Documentation

## ◆ ptr_

template<typename T >

T* xgboost::IntrusivePtr< T >::ptr_ {nullptr}
| protected

The documentation for this class was generated from the following file:

- /home/runner/work/xgboost/xgboost/include/xgboost/intrusive_ptr.h

xgboost::IntrusivePtrRefCount
IntrusivePtrCell & IntrusivePtrRefCount(T const *ptr) noexcept
User defined function for returing embedded reference count.