随笔分类 -  B---C++11特性

摘要:std::accumulate(std::begin(x), std::end(x), string(), [](string &ss, string &s){return ss.empty() ? s : ss + " " + s;}) ss是初始值 string(),相当于上一个值 s为当前遍历 阅读全文
posted @ 2022-07-22 23:51 douzujun 阅读(243) 评论(0) 推荐(0) 编辑
摘要:1. 生成了一个线程,需要告诉编译器是否管理 必须告诉编译器是不管理还是管理,否则直接down了 1.1 可以通过join(),自己管理 如果遇到异常,没有调用join,自己可以写一个析构调用join() 1.2 通过detach(),不管理 detach适合不会出错,生命周期比整个程序短,不想管理 阅读全文
posted @ 2019-05-09 23:26 douzujun 阅读(775) 评论(0) 推荐(0) 编辑
摘要:1. 遇到的问题 计算结果不一致!三个线程共享一份资源,有的加了有的没加。 2. 解决 2.1 法一:不共享变量 2.2 法二:原子操作变量类型(复杂,适合简单应用) b,c 线程共享了变量 counter2, 没有共享变量 totalValue,所以totalValue一样,counter2.co 阅读全文
posted @ 2019-05-05 21:09 douzujun 阅读(2991) 评论(0) 推荐(0) 编辑
摘要:1. 简单使用 阅读全文
posted @ 2019-05-03 15:41 douzujun 阅读(328) 评论(0) 推荐(0) 编辑
摘要:1. 不要自己手动管理资源 2. 一个裸指针不要用两个shared_ptr管理,unique_ptr 3. 使用shared_ptr作为函数的接口,如果有可能用 const shared_ptr&的形式 4. shared_ptr weak_ptr和裸指针相比,会大很多,并且效率上会有影响,尤其在多 阅读全文
posted @ 2019-05-02 23:56 douzujun 阅读(442) 评论(0) 推荐(0) 编辑
摘要:1. 几种智能指针 1. auto_ptr: c++11中推荐不使用他(放弃) 2. shared_ptr: 拥有共享对象所有权语义的智能指针 3. unique_ptr: 拥有独有对象所有权语义的智能指针 4. weaked_ptr: 到 std::shared_ptr 所管理对象的弱引用 1.1 阅读全文
posted @ 2019-05-02 21:40 douzujun 阅读(544) 评论(0) 推荐(0) 编辑
摘要:1. 几种智能指针 1. auto_ptr: c++11中推荐不使用他(放弃) 2. shared_ptr: 拥有共享对象所有权语义的智能指针 3. unique_ptr: 拥有独有对象所有权语义的智能指针 4. weaked_ptr: 到 std::shared_ptr 所管理对象的弱引用 1.1 阅读全文
posted @ 2019-05-02 20:58 douzujun 阅读(2994) 评论(0) 推荐(0) 编辑
摘要:1. 几种智能指针 1. auto_ptr: c++11中推荐不使用他(放弃) 2. shared_ptr: 拥有共享对象所有权语义的智能指针 3. unique_ptr: 拥有独有对象所有权语义的智能指针 4. weaked_ptr: 到 std::shared_ptr 所管理对象的弱引用 1.1 阅读全文
posted @ 2019-04-29 23:55 douzujun 阅读(1114) 评论(0) 推荐(0) 编辑
摘要:参考:https://www.cnblogs.com/cly-blog/p/5980546.html 阅读全文
posted @ 2019-04-29 23:31 douzujun 阅读(1358) 评论(0) 推荐(1) 编辑
摘要:1. auto推断变量类型 2. auto遍历 3. 自定义类可使用auto 阅读全文
posted @ 2019-04-29 22:17 douzujun 阅读(185) 评论(0) 推荐(0) 编辑
摘要:1. alignas (c++11) 设置类和struct的字节对齐方式 默认取值是: 2n : 0, 1, 2, 4 , 6, 8..... 2. alignof 区分sizeof(), alignof得到字节对齐的字节数 3. auto (c++11) 4. bitand 和 bitor 5. 阅读全文
posted @ 2019-04-10 20:05 douzujun 阅读(1365) 评论(0) 推荐(0) 编辑
摘要:c++11 c++14 阅读全文
posted @ 2019-04-06 01:17 douzujun 阅读(367) 评论(0) 推荐(0) 编辑
摘要:initializer_list 列表初始化 用花括号初始化器列表初始化一个对象,其中对应构造函数接受一个 std::initializer_list 参数. 阅读全文
posted @ 2019-03-29 11:42 douzujun 阅读(1816) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示