博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++ 知识点(不断更新)
阅读量:4210 次
发布时间:2019-05-26

本文共 2770 字,大约阅读时间需要 9 分钟。

1 .指针赋值

typedef tree_node
node_type;node_type* root;node_type **n =&root; //这里root虽然是个指针但是可能是空值,为了给指针赋值,所以取地址*n =new node_type(v,p,0,0);

2 . c++ callback 函数

Using StatusCallback = std::function
>使用template构造函数:// A generic for loop on GPUtemplate
__global__void loop_kernel( SizeT loop_size, OpT op){ const SizeT STRIDE = (SizeT)gridDim.x * blockDim.x; SizeT i = (SizeT)blockDim.x * blockIdx.x + threadIdx.x; while (i < loop_size) { op(i); i += STRIDE; }}

3 . 其中shared_ptr 指针初始化类似上面的:

template 
Status TorchOpContext
::AllocatePersistent( int64_t size, std::shared_ptr
* tensor) { // Allocation errors are handled using PyTorch exceptions. *tensor = std::make_shared
(device_, size); return Status::OK();}

4 . pair类型vector

std::vector
> layers;layers.push_back(std::make_pair(1,1));

5 . tuple类型vector

std::vector
> chunks;chunks.push_back(std::make_tuple( chunk_start, chunk_size, chunk_offset_bytes));SizeT chunk_start = std::get<0>(chunk);SizeT chunk_size = std::get<1>(chunk);size_t chunk_offset = std::get<2>(chunk);

6 . explict 关键字:禁止隐式构造函数

7 . typedef double(*func)();

8 . realloc : 动态内存分配

9 . c++ lambda 函数:

语法定义:[capture](parameters) mutable -> return-type{ statements }

10 . reinterpret_cast

unsigned int key_bits   = *reinterpret_cast
(const_cast
(&key));

11 . operation 相关重载函数

Operator: 相关的重载函数1. std::ostream & operator <<(std::ostream & out ,const half_t &x){             out<<(float)x;              return out;}     2. bool operator >=(const half_t & other) const{                return float(*this) >= float(other);}3. half_t & operator +=(const half_t &rhs){                *this =half_t(float(*this)+float(rhs));                reuturn &=*this;}4. operator float() const{                uint32_t f =0;                return *reinterpret_cast
(&f);}5. operator __half()const{ Return reinterpret_cast
(__x);}6. ++ 重载self_type &operator++(){ if(pos){ //首先确保不是空的迭代器,再查看有没有右子树 if(pos->right){ //定位到右子树的最左节点 pos=pos->right; while (pos->left)pos=pos->left; }else{ //定位到尚未访问过的祖先节点 while ((pos->parent)&&(pos->parent->right==pos))pos=pos->parent; pos=pos->parent; } } return *this;}7. 指针重载reference_type & operator *()const throw(std::runtime_error){ if(pos)return pos->value; else { throw std::runtime_error("dereference null iterator!"); }}8. != 重载template
bool operator !=(tree_iterator
const & left,tree_iterator
const & right){ return !(left==right);}

转载地址:http://wfwmi.baihongyu.com/

你可能感兴趣的文章
腾讯汤道生:开源已成为许多技术驱动型产业重要的创新推动力
查看>>
微信小程序多端框架 kbone 开源
查看>>
视频质量评估算法 DVQA 正式开源
查看>>
在中国提供了60亿次服务的疫情模块向世界开源 腾讯抗疫科技输出海外
查看>>
在中国提供了60亿次服务的疫情模块向世界开源
查看>>
世界卫生组织与腾讯加深合作 新冠肺炎AI自查助手全球开源
查看>>
Hibernate 中get, load 区别
查看>>
java反射详解
查看>>
JPA 注解
查看>>
JQuery 简介
查看>>
Java创建对象的方法
查看>>
Extjs自定义组件
查看>>
TreeGrid 异步加载节点
查看>>
Struts2 标签库讲解
查看>>
Google Web工具包 GWT
查看>>
材料与工程学科相关软件
查看>>
windows 下AdNDP 安装使用
查看>>
Project 2013项目管理教程(1):项目管理概述及预备
查看>>
ssh客户端后台运行
查看>>
哥去求职,才说了一句话考官就让我出去
查看>>