unique_ptr 中的 pointer() 是什么?
What is pointer() in unique_ptr?
我正在阅读 unique_ptr libstdc++ 中的源代码。
public:
typedef _Tp* pointer;
typedef _Tp element_type;
typedef _Tp_Deleter deleter_type;
// Constructors.
unique_ptr()
: _M_t(pointer(), deleter_type())
{ static_assert(!std::is_pointer<deleter_type>::value,
"constructed with null function pointer deleter"); }
我不understand.Does“pointer()”调用构造函数?但是“指针”是类型 _Tp*
的别名
这个表达式
pointer()
零初始化具有指针类型的 class 的数据成员 pointer
。对于指针类型,这意味着将指针设置为空指针。
来自 C++ 14 标准(8.5 初始化器)
11 An object whose initializer is an empty set of parentheses, i.e.,
(), shall be value-initialized
和
8 To value-initialize an object of type T means:
(8.4) — otherwise, the object is zero-initialized.
进一步
6 To zero-initialize an object or reference of type T means:
(6.1) — if T is a scalar type (3.9), the object is initialized to the
value obtained by converting the integer literal 0 (zero) to T;104
在脚注104中写着
- As specified in 4.10, converting an integer literal whose value
is 0 to a pointer type results in a null pointer value
对于所有类型,T()
是 value-initialises an unnamed instance of that type. For non-class, non-array types, value-initialisation is zero-initialisation
的表达式
the object's initial value is the integral constant zero explicitly converted to T
对于指针类型,这是一个空指针
我正在阅读 unique_ptr libstdc++ 中的源代码。
public:
typedef _Tp* pointer;
typedef _Tp element_type;
typedef _Tp_Deleter deleter_type;
// Constructors.
unique_ptr()
: _M_t(pointer(), deleter_type())
{ static_assert(!std::is_pointer<deleter_type>::value,
"constructed with null function pointer deleter"); }
我不understand.Does“pointer()”调用构造函数?但是“指针”是类型 _Tp*
的别名这个表达式
pointer()
零初始化具有指针类型的 class 的数据成员 pointer
。对于指针类型,这意味着将指针设置为空指针。
来自 C++ 14 标准(8.5 初始化器)
11 An object whose initializer is an empty set of parentheses, i.e., (), shall be value-initialized
和
8 To value-initialize an object of type T means:
(8.4) — otherwise, the object is zero-initialized.
进一步
6 To zero-initialize an object or reference of type T means:
(6.1) — if T is a scalar type (3.9), the object is initialized to the value obtained by converting the integer literal 0 (zero) to T;104
在脚注104中写着
- As specified in 4.10, converting an integer literal whose value is 0 to a pointer type results in a null pointer value
对于所有类型,T()
是 value-initialises an unnamed instance of that type. For non-class, non-array types, value-initialisation is zero-initialisation
the object's initial value is the integral constant zero explicitly converted to
T
对于指针类型,这是一个空指针