std::is_pointer是false为std::nullptr_t因为它不是内置的指针类型。 例 二次 代码语言:javascript 复制 #include <iostream> #include <type_traits> int main() { std::cout << std::boolalpha << std::is_null_pointer< decltype(nullptr) >::value << ' ' << std::is_null_pointer< int* >:...
std::is_null_pointer 定义于头文件<type_traits> template<classT> structis_null_pointer; (C++14 起) 检查T是否为std::nullptr_t类型。 若T为std::nullptr_t、conststd::nullptr_t、volatilestd::nullptr_t或constvolatilestd::nullptr_t类型,则提供等于true的成员常量value。
std::is_null_pointeris aUnaryTypeTrait. Checks whetherTis the typestd::nullptr_t. Provides the member constantvaluethat is equal totrue, ifTis the typestd::nullptr_t,conststd::nullptr_t,volatilestd::nullptr_t, orconstvolatilestd::nullptr_t. ...
std::is_nothrow_move_constructible std::is_nothrow_swappable std::is_nothrow_swappable_with std::is_null_pointer std::is_object std::is_placeholder std::is_pod std::is_pointer std::is_polymorphic std::is_reference std::is_rvalue_reference std::is_same std::is_scalar std::is_signed ...
std::is_void std::is_null_pointer std::is_array std::is_pointer std::is_enum std::is_union std::is_class std::is_function std::is_object std::is_scalar std::is_compound std::is_floating_point std::is_fundamental std::is_arithmetic std::is_reference std::is_lvalue_reference std...
std::is_nothrow_move_constructible std::is_nothrow_swappable std::is_nothrow_swappable_with std::is_null_pointer std::is_object std::is_placeholder std::is_pod std::is_pointer std::is_polymorphic std::is_reference std::is_rvalue_reference std::is_same std::is_scalar std::is_signed ...
std::is_nothrow_move_assignable std::is_nothrow_move_constructible std::is_nothrow_swappable std::is_nothrow_swappable_with std::is_null_pointer std::is_object std::is_placeholder std::is_pod std::is_pointer std::is_polymorphic std::is_reference std::is_rvalue_reference std::is_same ...
std::any a; // a is empty std::any b = 4.3; // b has value 4.3 of type double a = 42; // a has value 42 of type int b = std::string{"hi"}; // b has value "hi" of type std::string if (a.type() == typeid(std::string)) ...
}intmain(){int*pi{};double*pd{};f(pi);f(pd);f(nullptr);// would be ambiguous without void f(nullptr_t)// f(0); // ambiguous call: all three functions are candidates// f(NULL); // ambiguous if NULL is an integral null pointer constant// (as is the case in most ...
Ptr = std::make_shared<std::vector<int>>(); // 检查指针是否为空 if (vecPtr) { vecPtr->push_back(1); vecPtr->push_back(2); vecPtr->push_back(3); // 安全地使用引用 processVector(*vecPtr); } else { std::cerr << "Error: vecPtr is null!