首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::is_scalar

Defined in header <type_traits>

template< class T > struct is_scalar;

(since C++11)

如果T是标量型%28,这可能是cv-合格的。算术,指针,指向成员的指针,,,枚举,或std::nullptr_t类型%29,提供成员常量value平等true.对于任何其他类型,valuefalse...

模板参数

T

-

a type to check

辅助变量模板

template< class T > inline constexpr bool is_scalar_v = is_scalar<T>::value;

(since C++17)

继承自STD:积分[医]常量

成员常数

value static

true if T is a scalar type , false otherwise (public static member constant)

成员函数

operator bool

converts the object to bool, returns value (public member function)

operator() (C++14)

returns value (public member function)

成员类型

Type

Definition

value_type

bool

type

std::integral_constant<bool, value>

注记

C++内存模型中的每个单独的内存位置,包括语言使用的隐藏内存位置都具有%28e的特性。g虚拟表指针%29,具有标量类型%28或是序列的相邻位字段的长度为%29。表达式评估、线程间同步和依赖排序中的副作用排序都是根据单个标量对象定义的。

可能的实施

模板<class T>结构是[医]标量:STD::整数[医]常数<bool,std::is[医]算术<T>*价值STD::是[医]枚举<T>*价值STD::是[医]指针<T>*价值STD::是[医]成员[医]指针<T>*价值STD::是[医]零[医]指针<T>*价值>{};

*。

二次

代码语言:javascript
复制
#include <iostream>
#include <type_traits>
 
int main() {
    class cls {};
    std::cout << (std::is_scalar<int>::value
                     ? "T is a scalar"
                     : "T is not a scalar") << '\n';
    std::cout << (std::is_scalar<cls>::value
                     ? "T is a scalar"
                     : "T is not a scalar") << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
T is a scalar
T is not a scalar

二次

另见

is_arithmetic (C++11)

checks if a type is arithmetic type (class template)

is_enum (C++11)

checks if a type is an enumeration type (class template)

is_pointer (C++11)

checks if a type is a pointer type (class template)

is_member_pointer (C++11)

checks if a type is a pointer to a non-static member function or object (class template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券