#include <iostream>
using namespace std;
int main()
{
int a = 5;
add_const<int *>::type b = &a;//int * const
//关于引用遵守引用折叠规则
add_lvalue_reference<int&&>::type c = a;// int &
add_rvalue_reference<int&>::type d = a; // int &
add_pointer<int>::type e = &a; //int*
//传入reference会导致不明确行为
make_signed<unsigned>::type f = -5; // int
make_unsigned<int>::type g = 5;//unsigned
//去除row const
remove_const<decltype(b)>::type m = &a;// int*
remove_reference<int&&>::type n = 5;//int
remove_pointer<int*>::type j = 6;//int
//去除row volatile
remove_volatile<int *volatile>::type i = &a; //int*
remove_cv<const int *volatile>::type k = &a; // const int*
add_volatile<int>::type w = 4;// volatile int
add_cv<int*>::type v = &a; // int*volatile const
system("pause");
return 0;
}
c++ type trait 之 类型修饰符(Type Modifier)改动类型
最新推荐文章于 2025-02-03 00:00:00 发布
本文通过一个C++示例程序介绍了类型特质的使用方法,包括添加和移除const、volatile限定符,以及如何处理左值引用、右值引用和指针等。展示了通过模板元编程实现类型操作的具体应用。
2980

被折叠的 条评论
为什么被折叠?



