xgboost
| 公共类型 | 公共成员函数 | 受保护属性 | 所有成员列表
xgboost::IntrusivePtr< T > 类模板参考

侵入式指针的实现。一个智能指针,指向一个嵌入了引用计数器的对象。底层对象必须实现一个友元函数IntrusivePtrRefCount(),该函数返回引用计数器(类型为IntrusivePtrCell)。侵入式指针比std::shared_ptr<>更快:std::shared_ptr<>为引用计数器进行了额外的内存分配,而侵入式指针则没有。更多...

#include <intrusive_ptr.h>

xgboost::IntrusivePtr< T > 的协作图
Collaboration graph

结构  哈希
 

公共类型

使用 element_type = T
 

公共成员函数

 IntrusivePtr (T *p)
 从原始指针构造一个IntrusivePtrIntrusivePtr取得所有权。更多...
 
 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_typeoperator* () const noexcept
 
element_typeoperator-> () const noexcept
 
element_typeget () const noexcept
 
 operator bool () const noexcept
 
int32_t use_count () noexcept
 
void swap (IntrusivePtr< T > &that) noexcept
 

保护属性

T * ptr_ {nullptr}
 

详细描述

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

侵入式指针的实现。一个智能指针,指向一个嵌入了引用计数器的对象。底层对象必须实现一个友元函数IntrusivePtrRefCount(),该函数返回引用计数器(类型为IntrusivePtrCell)。侵入式指针比std::shared_ptr<>更快:std::shared_ptr<>为引用计数器进行了额外的内存分配,而侵入式指针则没有。

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};
IntrusivePtrCell & IntrusivePtrRefCount(T const *ptr) noexcept
用于返回嵌入式引用计数的自定义函数。

成员类型定义文档

◆ element_type

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

构造函数和析构函数文档

◆ IntrusivePtr() [1/4]

template<typename T >
xgboost::IntrusivePtr< T >::IntrusivePtr ( T *  p)
内联显式

从原始指针构造一个IntrusivePtrIntrusivePtr取得所有权。

参数
p指向对象的原始指针

◆ IntrusivePtr() [2/4]

template<typename T >
xgboost::IntrusivePtr< T >::IntrusivePtr ( )
defaultnoexcept

◆ 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)
inlinenoexcept

◆ ~IntrusivePtr()

template<typename T >
xgboost::IntrusivePtr< T >::~IntrusivePtr ( )
inline

成员函数文档

◆ get()

template<typename T >
element_type* xgboost::IntrusivePtr< T >::get ( ) const
inlinenoexcept

◆ operator bool()

template<typename T >
xgboost::IntrusivePtr< T >::operator bool ( ) const
inlineexplicitnoexcept

◆ operator*()

template<typename T >
element_type& xgboost::IntrusivePtr< T >::operator* ( ) const
inlinenoexcept

◆ operator->()

template<typename T >
element_type* xgboost::IntrusivePtr< T >::operator-> ( ) const
inlinenoexcept

◆ operator=() [1/2]

template<typename T >
IntrusivePtr<T>& xgboost::IntrusivePtr< T >::operator= ( IntrusivePtr< T > &&  that)
inlinenoexcept

◆ 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)
inlinenoexcept

◆ use_count()

template<typename T >
int32_t xgboost::IntrusivePtr< T >::use_count ( )
inlinenoexcept

成员数据文档

◆ ptr_

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

此类的文档由以下文件生成