Medial Code Documentation
Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions | Protected Attributes
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>

Data Structures

struct  Hash
 

Public Types

using element_type = T
 

Public Member Functions

 IntrusivePtr (T *p)
 Contruct an IntrusivePtr from raw pointer. IntrusivePtr takes the ownership.
 
 IntrusivePtr (IntrusivePtr const &that)
 
 IntrusivePtr (IntrusivePtr &&that) noexcept
 
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 };
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};
Helper class for embedding reference counting into client objects. See https://www....
Definition intrusive_ptr.h:20
IntrusivePtrCell & IntrusivePtrRefCount(T const *ptr) noexcept
User defined function for returning embedded reference count.

Constructor & Destructor Documentation

◆ IntrusivePtr()

template<typename T >
xgboost::IntrusivePtr< T >::IntrusivePtr ( T *  p)
inlineexplicit

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

Parameters
pRaw pointer to object

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