C++
丸子叮咚响
日拱一卒,功不唐捐。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C++ STL 算法汇总
非更易型算法 更易型算法 移除区间元素算法 变序型算法 排序算法 已排序区间算法 数值算法原创 2022-02-10 16:28:35 · 401 阅读 · 0 评论 -
C++ 那些被遗漏的细节7 std::list::merge
之前有演示过std::merge的用法,参见C++ 算法 归并元素 然后看下std::list::merge的例子 #include <iostream> #include <list> std::ostream& operator<<(std::ostream& ostr, const std::list<int>& list) { for (auto &i : list) { ostr &..原创 2021-09-07 19:33:44 · 702 阅读 · 0 评论 -
C++ 那些被遗漏的细节6 shared_ptr owner_before
语法 // <memory> // template< class T > class shared_ptr; (since C++11) template< class Y > bool owner_before( const shared_ptr<Y>& other) const noexcept; template< class Y > bool owner_before( const std::weak_ptr<Y>&a原创 2021-07-22 09:45:59 · 337 阅读 · 0 评论 -
C++ 那些被遗漏的细节5 shared_ptr别名构造函数
概述 shared_ptr的基本使用可以参考之前文章: C++11 shared_ptr weak_ptr。 别名构造函数 // cppreference template< class T > class shared_ptr;(since C++11) // 别名构造函数 template< class Y > shared_ptr( const shared_ptr<Y>& r, element_type* ptr ) noexcept; c原创 2021-07-21 20:08:21 · 565 阅读 · 0 评论 -
C++ 那些被遗漏的细节4 std::piecewise_construct_t
简述 在以前的文章C++ std::pair 有对std::pair做简单介绍。 需要注意的是std::pair有一个特别的构造函数,第一个参数类型为std::piecewise_construct_t, 实际就是一个空结构体类型,用作标识。 std::piecewise_construct_t作用就是其字面意思:分段构造。具体来说,因pair的key和value均可以是构造函数复杂类型,因而pair的初始化相对复杂,通过带有std::piecewise_construct_t类型参数,后跟两个tuple原创 2021-07-13 11:43:50 · 2917 阅读 · 0 评论 -
C++ 那些被遗漏的细节3 std::get
简述 在之前的文章C++11 std::tuple 中使用std::get获取std::tuple元素的例子。 std::get除了通过索引(C++11)获取std::tuple的元素,还能通过元素类型获取元素(C++14) 语法 // 头文件 <tuple> template< std::size_t I, class... Types > typename std::tuple_element<I, tuple<Types...> >::type&am原创 2021-07-12 18:50:41 · 6855 阅读 · 0 评论 -
C++ 那些被遗漏的细节2 map emplace emplace_hint
说明 主要关注map的emplace、insert的返回类型 std::pair<iterator, bool> 和 emplace_hint的返回类型iterator。 template< class... Args > std::pair<iterator,bool> emplace( Args&&... args );(since C++11) 如果插入成功,则iterator指向新插入元素,否则指向已存在的相同key元素;插入成功bool为原创 2021-07-08 19:46:07 · 857 阅读 · 0 评论 -
C++ 那些被遗漏的细节1 find_first_of
show code #include <iostream> #include <string> int main() { std::string str = "hello world"; std::string sign = "wo"; std::cout << "position: " << str.find_first_of(sign) << std::endl; return 0; } 结果 position: 4原创 2021-06-23 20:23:55 · 268 阅读 · 0 评论
分享