一:alignas 设置对其方式
#include <iostream>
using namespace std;
struct test1
{
char a;
int b;
double c;
};
struct alignas(8) test2
{
char a;
int b;
double c;
};
struct alignas(16) test3
{
char a;
int b;
double c;
};
struct alignas(32) test4
{
char a;
int b;
double c;
};
struct alignas(64) test5
{
char a;
int b;
double c;
};
int main()
{
test1 t1;
test2 t2;
test3 t3;
test4 t4;
test5 t5;
cout << "t1 size" << sizeof (t1) << '\n'
<< "t2 size" << sizeof (t2) << '\n'
<< "t3 size" << sizeof (t3) << '\n'
<< "t4 size" << sizeof (t4) << '\n'
<< "t5 size" << sizeof (t5) << '\n'
<< endl;
return 0;
}
输出
t1 size16
t2 size16
t3 size16
t4 size32
t5 size64
二:alignof
struct alignas(32) test4
{
char a;
int b;
double c;
double d;
double e;
double f;
double g;
};
struct alignas(64)
{};
int main()
{
std::cout << alignof(test4) << '\n';
return 0;
}
输出32 和64
三:and_eq(&=)
#include <iostream>
#include <bitset>
int main()
{
bitset<4> mask("1010");
bitset<4> mink("1011");
mask &= mink;
std::cout << mask << '\n';
return 0;
}
输出 :1010 (Qt中似乎不支持and_eq的写法)
四:is_integral
is_integral 是一个模板,完整形式 is_integral<T>::value,用来判断传进来的参数T是否是int 类型
#include <iostream>
using namespace std;
int main()
{
if(is_integral<char>::value)
std::cout << "char is a int type\n";
if(!is_integral<double>::value)
std::cout << "double is not a int type"
}
程序输出:
char is a int type
double is not a int type