自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(11)
  • 收藏
  • 关注

原创 C++ 类型推导(四)获取编译器推导出的类型

获取编译器推导出的类型 ide 编译时获知 template<typename T> class TD; auto x = 10; TD<decltype(x)> x_type; 编译时由于类TD未定义,会打印错误信息,包含了x的类型 标准库工具tyepid auto x = 10; std::cout<<typeid(x).name()<<std::endl; boost/type_index.hpp 前面的方法由于标准的原因,得到的结果都会有所不

2021-04-14 17:04:54 237

原创 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))->bool struct Point{ int x,y; } 利用decltype实现函数返回值的类型推导(c++11) template&lt

2021-04-14 16:57:42 168

原创 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 deduce template <typename T> void f(std::initializer_

2021-04-14 16:26:25 162

原创 c++类型推导(一)模板推导

模板推导 指针或者引用(不为通用引用) 多退少补 为引用时 如果传入参数是引用则忽略引用部分,其他部分照常处理 template<typename T> void f(T& param); int x = 27; const int cx = x; const int& rx = x; f(x);//T->int,param->int f(cx);//T->const int,param->const int f(rx);//T->const i

2021-04-13 22:29:38 321

原创 c++ 构造、复制、析构

文章目录title构造函数拷贝构造函数合成拷贝构造函数拷贝初始化的调用场景拷贝赋值函数移动构造函数移动赋值函数析构函数other title 构造函数 使用explicit消除隐式类型转换,编译器只允许一次的自动类型转换 拷贝构造函数 合成拷贝构造函数 即使已经定义了一个拷贝构造函数,编译器还是会产生一个默认的拷贝构造函数,其将对应的值挨个进行拷贝。 拷贝初始化的调用场景 将一个对象作为实参传递给一个非引用类型的形参 从一个返回类型为非引用类型的函数返回一个对象(栈上的对象必须被销毁) 用花括号列表初

2021-04-13 17:52:08 307

原创 C++ stringstream 重复使用

#include<string> #include<sstream> using namespace std; int main() { int n1 = 2, n2 = 3; string s1, s2; stringstream ss; ss << n1 << n2; ss >> s1; ss.str("");//清空buffer ss.clear();//初始化流状态 ss &l

2021-04-13 15:54:14 675

原创 C++ concurrency in action (二)

文章目录C++ 并发编程(同步)条件变量`future``std::sync``std::packaged_task``std::primise`异常处理多个线程同时等待 C++ 并发编程(同步) 条件变量 条件变量的使用见c++11 实现线程安全队列 future future的提出是为了解决当一个事件发生并没有那么频繁,使用条件变量会显得过于麻烦的场景。例如乘坐飞机和上课的频繁程度。 在c++中有两种实现 std::future<> std::shared_future<> //

2021-04-11 20:24:26 551

原创 c++ concurrency in action (一)

文章目录c++11 中的锁`mutex``mutex`配合`std::lock_guard`使用同时对多个`mutex`上锁配合`std::unique_lock`使用`std::call_once`的使用`recursive locking` c++11 中的锁 mutex mutex 头文件:mutex 使用方法: //声明 std::mutex some_mutex; //加锁 some_mutex.lock(); some_mutex.try_lock(); std::lock(some_mut

2021-04-11 18:09:10 335

原创 c++11 实现线程安全队列

#include<thread> #include<cstdio> #include<mutex> #include<list> #include<condition_variable> #include<memory> #include<chrono> class Queue{ private: std::list<int> data_queue_; std::condition_va.

2021-04-11 16:43:46 301

转载 c++ string find 方法

size_t find (const string& str, size_t pos = 0) const noexcept; size_t find (const char* s, size_t pos = 0) const; size_t find (const char* s, size_t pos, size_type n) const; size_t find (char c, size_t pos = 0) const noexcept; 查找目的字符串中str的首次出现位置,str可

2021-04-08 19:24:45 291

原创 socket 基本API

socket 基本API 地址结构 ipv4地址结构 <netinet/in.h> struct in_addr{ in_addr_t s_addr; } struct sockaddr_in{ uint8_t sin_len; sa_family_t sin_family; in_port_t sin_port; struct in_addr sin_addr; char sin_zero[8]; } ipv6 地址结构 <netinet/in.h> struct in6

2021-03-19 19:50:37 82

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除