C++11
DBBH
成都有合适webgl岗位的请私信我
展开
-
记一下几种智能指针区别
这个好 unique_ptr就是独有,不能复制,赋值,通过move可以转移 shared_prt可以赋值复制,也可以用move,move就不会增加引用计数 要把包含this的shared_ptr交给另外的对象管理的话要shared_from_this,还得继承一个类 weak_ptr 这个没有引用计数 用来打破shared_prt循环引用 ...原创 2022-01-12 10:31:17 · 420 阅读 · 0 评论 -
std::move
他滴实现 template typename std::remove_reference::type&& move(T&&t) { static_cast::type&&>(t); } 然后这个是remove_reference template struct remove_reference{ typedef T type}; template struct remove_r原创 2017-01-11 11:35:34 · 220 阅读 · 0 评论 -
std::function
源码 template class function; 例子 void func(int a){ std::cout }; std::functionf=func;//函数类型 参数类型 f(10); std::functionf=std::bind( func,_1 );//std::functionf=std::bind( func, 10 ); f(10)原创 2017-01-11 21:16:17 · 225 阅读 · 0 评论 -
学习变参模板
看滴是C++ Primer 5中文的。。 template ostream&Print(ostream&os,const T&t,const Args&...args> { os return Print(os,args...); } 这样子就可以一直递归到没有扩展包。。然后写个没包的结个尾 template ostream &Print(ostream&os,const T&原创 2017-01-17 23:30:09 · 181 阅读 · 0 评论 -
std::bind
源码 template bind(F&& f , Args&&...args); 例子 void func(int a,int b) { std::cout } struct Foo { void p(int a,int b){ cout } } auto f=std::bind(func,_1,_2);f(1,3)=4 //auto f=std::bind(fun原创 2017-01-11 17:14:14 · 244 阅读 · 0 评论 -
C++变参模板简单使用
为什么简单使用呢 因为目前没遇到实际应用的地方 就大概学一下吧 template void print(T t,A...a) { std::cout print(a...);//这个函数是通用情况 } template void print(T t) { std::cout } 就简单的打印不定数量参数原创 2018-02-05 23:15:46 · 430 阅读 · 0 评论 -
C++11简易线程池
#include<iostream>#include<functional>#include<thread>#include<condition_variable>#include<mutex>#include<queue>#define ThreadNum 555#define POOL Pusing namespace s...原创 2018-02-26 15:55:47 · 191 阅读 · 0 评论 -
简单试用std::lock_guard
#include<iostream>#include<mutex>#include<thread>using namespace std;std::mutex mutx;void func(){ std::lock_guard<std::mutex> l(mutx);//局部变量 析构的时候顺便解锁 for (int i = 0; i <...原创 2018-02-12 22:44:06 · 400 阅读 · 0 评论 -
C++11学习生产者消费者
就是有一个东西 有人生产有人用#include<iostream>#include<thread>#include<mutex>#include<condition_variable>#include<list>#include<memory>using namespace std;#define MaxSize 5std...原创 2018-02-24 16:17:05 · 215 阅读 · 0 评论