上一页 1 ··· 3 4 5 6 7 8 9 10 11 12 下一页
摘要: 1 #include "MyHashTable.h" 2 template <typename Tp> 3 struct Identity 4 { 5 const Tp& operator()(const Tp& x) const { return x; } 6 }; 7 template <typ 阅读全文
posted @ 2021-02-25 20:43 ho966 阅读(62) 评论(0) 推荐(0) 编辑
摘要: hash_map 1 template <class Pair> 2 struct Select1st 3 { 4 const typename Pair::first_type& operator()(const Pair& x) const 5 { 6 return x.first; 7 } 8 阅读全文
posted @ 2021-02-25 20:42 ho966 阅读(140) 评论(0) 推荐(0) 编辑
摘要: c++11之前,标准库里的哈希容器是std::hash_set、std::hash_multiset、std::hash_map、std::hash_multisetmap; c++11之后,他们的名字改成了std::unorder_set、std::unorder_multiset、std::un 阅读全文
posted @ 2021-02-25 20:40 ho966 阅读(89) 评论(0) 推荐(0) 编辑
摘要: valgrind是很好的检查内存泄漏的工具 使用命令: $ valgrind --tool=memcheck --log-file=/root/valgrind_log_all --leak-check=full --error-limit=no --show-reachable=yes --tra 阅读全文
posted @ 2021-02-18 11:29 ho966 阅读(185) 评论(0) 推荐(0) 编辑
摘要: void Printf(const char* s) { while (*s) { std::cout << *s++; } } template <typename T, typename... Types> void Printf(const char* s, const T& firstArg 阅读全文
posted @ 2021-02-05 13:02 ho966 阅读(129) 评论(0) 推荐(0) 编辑
摘要: std::bitset<size_t size> 1、bitset提供了位操作,模板参数就是位的个数; 2、其内部数据结构是long数组,一个long可以表示32位,所以避免浪费,最好取32的倍数 3、bitset提供转std::string的接口,其构造函数入参也支持std::string, 需要 阅读全文
posted @ 2021-02-03 11:30 ho966 阅读(406) 评论(0) 推荐(0) 编辑
摘要: 1、noexcept 告知编译器不会丢出异常异常,可以放心优化。对于std::vetcor,其申请新申请内存成长时,元素的移植构造函数必须有noexcept关键字,否则只会调用拷贝构造 用法: void foo() noexcept {} 2、override 告知编译器该函数是继承父类函数的,编译 阅读全文
posted @ 2021-01-30 14:56 ho966 阅读(56) 评论(0) 推荐(0) 编辑
摘要: 以前定义一个类型都是用typedef, 例如一个函数指针的类型 typedef void(*func)(void) c++新特性支持下面这样去定义,效果一样 using func = void(*)(void) 阅读全文
posted @ 2021-01-30 14:12 ho966 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 使用c++智能指针需要包含头文件<memory>,对于SGI版本的STL, shared_ptr、weak_ptr实现在<bits/shared_ptr.h>中,unique_ptr实现在<bits/unique_ptr.h>中 1、 shared_ptr 作用:通过应用计数实现自动释放指针,用户不 阅读全文
posted @ 2021-01-30 11:02 ho966 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 1、使用举例: std::vector<int> a{1,2,3}; // 列表初始化 编译器会将大括号{}转换为std::initializer_list,编译器会调用 std::initializer_list的私有构造函数,生成vector的入参,所以vector里面有一个入参是initial 阅读全文
posted @ 2021-01-25 13:13 ho966 阅读(588) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 12 下一页