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

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

#include <intrusive_ptr.h>

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

struct  Hash
 

公共类型

using 元素类型 = 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 重置 ()
 
void 重置 (元素类型 *that)
 
元素类型operator* () const noexcept
 
元素类型operator-> () const noexcept
 
元素类型get () const noexcept
 
 operator bool () const noexcept
 
int32_t 引用计数 () noexcept
 
void 交换 (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
用于返回嵌入式引用计数器的用户定义函数。

成员类型定义文档

◆ 元素类型

template<typename T >
using xgboost::IntrusivePtr< T >::元素类型 = T

构造函数和析构函数文档

◆ IntrusivePtr() [1/4]

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

从裸指针构造一个 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 >
元素类型* xgboost::IntrusivePtr< T >::get ( ) const
inlinenoexcept

◆ operator bool()

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

◆ operator*()

template<typename T >
元素类型& xgboost::IntrusivePtr< T >::operator* ( ) const
inlinenoexcept

◆ operator->()

template<typename T >
元素类型* 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

◆ 重置() [1/2]

template<typename T >
void xgboost::IntrusivePtr< T >::重置 ( )
inline

◆ 重置() [2/2]

template<typename T >
void xgboost::IntrusivePtr< T >::重置 ( 元素类型 that)
inline

◆ 交换()

template<typename T >
void xgboost::IntrusivePtr< T >::交换 ( IntrusivePtr< T > &  that)
inlinenoexcept

◆ 引用计数()

template<typename T >
int32_t xgboost::IntrusivePtr< T >::引用计数 ( )
inlinenoexcept

成员数据文档

◆ ptr_

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

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