
Effective C++
maxmit
这个作者很懒,什么都没留下…
展开
-
C++ 类型推导(四)获取编译器推导出的类型
获取编译器推导出的类型ide编译时获知template<typename T>class TD;auto x = 10;TD<decltype(x)> x_type;编译时由于类TD未定义,会打印错误信息,包含了x的类型标准库工具tyepidauto x = 10;std::cout<<typeid(x).name()<<std::endl;boost/type_index.hpp前面的方法由于标准的原因,得到的结果都会有所不原创 2021-04-14 17:04:54 · 253 阅读 · 0 评论 -
C++ 类型推导(三)decltype关键字
decltype 关键字decltype 关键字会保留一个类型的所有信息const int i = 0;//decltype(i)->const int bool f(const Widget&w);//decltype(f)-> bool (const Widget&); //decltype(f(w))->boolstruct Point{int x,y;}利用decltype实现函数返回值的类型推导(c++11)template<原创 2021-04-14 16:57:42 · 174 阅读 · 0 评论 -
C++ 类型推导(二)auto关键字
auto 关键字auto 关键字和模板推导的规则大体一致,但是在面对初始化列表时,有所不同。auto与初始化列表auto a = {1,2,3}//a->std::initialize_list<int>函数模板与初始化列表template <typename T>void f(T param)f({1,2,3})//error can't deducetemplate <typename T>void f(std::initializer_原创 2021-04-14 16:26:25 · 172 阅读 · 0 评论 -
c++类型推导(一)模板推导
模板推导指针或者引用(不为通用引用)多退少补为引用时如果传入参数是引用则忽略引用部分,其他部分照常处理template<typename T>void f(T& param);int x = 27;const int cx = x;const int& rx = x;f(x);//T->int,param->intf(cx);//T->const int,param->const intf(rx);//T->const i原创 2021-04-13 22:29:38 · 322 阅读 · 0 评论