随笔分类 -  ANSI C++

摘要:1. hash工具类hashval.hpp#ifndef _Core_HashVal_H_#define _Core_HashVal_H_#include // from boost (functional/hash):// see http://www.boost.org/doc/libs/1_3... 阅读全文
posted @ 2015-12-18 11:42 Master HaKu 阅读(1863) 评论(0) 推荐(0) 编辑
摘要:一些简单操作UnorderedSetTest.cpp#include #include #include "../../Core/print.hpp"#include "UnorderedSetTest.h"using namespace std;void UnorderedSetTest::sim... 阅读全文
posted @ 2015-11-26 16:14 Master HaKu 阅读(2354) 评论(1) 推荐(0) 编辑
摘要:RuntimeStringCmp.cpp#include using namespace std;// function object to compare strings// - allows you to set the comparison criterion at runtime// - a... 阅读全文
posted @ 2015-11-18 11:43 Master HaKu 阅读(743) 评论(0) 推荐(0) 编辑
摘要:把Map用作关联式数组MapAdvanceTest.cpp#include #include #include #include #include "MapAdvanceTest.h"#include "../../Core/ContainerUtil.h"using namespace std;v... 阅读全文
posted @ 2015-11-04 15:53 Master HaKu 阅读(197) 评论(0) 推荐(0) 编辑
摘要:MapTest.cpp#include #include #include #include #include "MapTest.h"using namespace std;void MapTest::simpleEnumeration(){ map coll { { "tim... 阅读全文
posted @ 2015-10-28 14:15 Master HaKu 阅读(151) 评论(0) 推荐(0) 编辑
摘要:RuntimeCmp.hpp#include using namespace std;// type for runtime sorting criterionclass RuntimeCmp {public: enum cmp_mode { normal, reverse };private... 阅读全文
posted @ 2015-10-26 11:08 Master HaKu 阅读(357) 评论(0) 推荐(0) 编辑
摘要:MultiSet根据特定排序准则,自动将元素排序。MultiSet允许元素重复。一些常规操作:MultiSetTest.cpp#include #include #include #include #include #include "MultiSetTest.h"using namespace s... 阅读全文
posted @ 2015-10-22 09:55 Master HaKu 阅读(233) 评论(0) 推荐(0) 编辑
摘要:Set根据特定排序准则,自动将元素排序。Set不允许元素重复。一些常规操作:SetTest.cpp#include #include #include #include #include #include "SetTest.h"using namespace std;void SetTest::op... 阅读全文
posted @ 2015-10-21 20:56 Master HaKu 阅读(233) 评论(0) 推荐(0) 编辑
摘要:forward list是一个行为受限的list, 不能走回头路。它只提供前向迭代器, 而不提供双向迭代器。eg:rbegin(), rend(), crbegin(), crend()这些都不提供。它不提供size()成员函数。没有指向最末元素的anchor, 因此不提供back(), push_... 阅读全文
posted @ 2015-10-19 15:10 Master HaKu 阅读(278) 评论(0) 推荐(0) 编辑
摘要:List内部结构完全不同于array, vector, deque。它提供了两个pointer,指向第一个和最后一个元素。不支持随机访问元素,因此要访问第n个元素必须爬过n - 1个元素。在任何位置上执行元素的插入和删除操作都很快。因此会有一些属于list的特殊类型操作,比如merge, splic... 阅读全文
posted @ 2015-10-16 10:41 Master HaKu 阅读(155) 评论(0) 推荐(0) 编辑
摘要:Deque和Vector类似,只不过deque头尾都开放,能够在头尾进行快速插入和删除操作DequeTest.cpp#include #include #include #include #include #include "DequeTest.h"using namespace std;void ... 阅读全文
posted @ 2015-10-14 10:13 Master HaKu 阅读(142) 评论(0) 推荐(0) 编辑
摘要:VectorTest.cpp#include #include #include #include #include #include "VectorTest.h"using namespace std;void VectorTest::simpleOperation(){ // create... 阅读全文
posted @ 2015-10-13 10:20 Master HaKu 阅读(294) 评论(0) 推荐(0) 编辑
摘要:Array是C++ 11给STL新增加的容器ArrayTest.cpp#include #include #include #include #include "../../Core/print.hpp"#include "ArrayTest.h"using namespace std;void A... 阅读全文
posted @ 2015-10-12 16:40 Master HaKu 阅读(185) 评论(0) 推荐(0) 编辑
摘要:1. 预定义函数对象C++标准库内含许多预定义的函数对象,也就是内置的函数对象。你可以充分利用他们,不必自己费心去写一些自己的函数对象。要使用他们,你只要包含如下头文件#include eg:set> coll; // sort elements with > coll; // sort eleme... 阅读全文
posted @ 2015-09-29 14:49 Master HaKu 阅读(300) 评论(0) 推荐(0) 编辑
摘要:我们再来看一个复杂的例子需求:我们需要对集合内每个元素加上一个特定的值代码如下:AddInt.hclass AddInt{private: int theValue; // the value to addpublic: // constructor initializes the... 阅读全文
posted @ 2015-09-25 11:46 Master HaKu 阅读(247) 评论(0) 推荐(0) 编辑
摘要:1. 定义在STL中,可以把函数传递给算法,也可以把函数对象传递给算法。那么,什么是函数对象呢?我们来看下它的声明:class X{public: // define function call operator return-value operator() (arguments) const... 阅读全文
posted @ 2015-09-22 15:34 Master HaKu 阅读(3330) 评论(0) 推荐(0) 编辑
摘要:关于lambda的基础知识,请参考上一篇的地址如下:http://www.cnblogs.com/davidgu/p/4825625.html我们再举个STL使用Lambda来进行排序的例子,如下:Person.h#ifndef _Domain_Models_Person_H_#define _Do... 阅读全文
posted @ 2015-09-21 13:01 Master HaKu 阅读(409) 评论(0) 推荐(0) 编辑
摘要:Lambda始自C++ 11,是一种在表达式或语句内指定函数行为的定义式。你可以定义函数行为作为对象,以inline实参的形式传给算法作为predicate(判断式)。eg:std:transform(coll.begin(), coll.end(), // sourcecoll.begin(),/... 阅读全文
posted @ 2015-09-21 11:26 Master HaKu 阅读(3058) 评论(0) 推荐(0) 编辑
摘要:Binary Predicate(双参判断式)的用途是:比较两个参数的特定属性我们先建一个领域模型类:Person.h#ifndef _Domain_Models_Person_H_#define _Domain_Models_Person_H_#include #include #include ... 阅读全文
posted @ 2015-09-17 11:43 Master HaKu 阅读(1108) 评论(0) 推荐(0) 编辑
摘要:Predicate是一种特殊的辅助函数,它会返回Boolean,常常被用来作为排序或者查找准则。Predicate会有1个或者2个操作数。Unary Predicate(单参判断式)例子:我们先写一个算法,如下:MathUtil.h#ifndef _Math_Util_H_#define _Math... 阅读全文
posted @ 2015-09-17 09:58 Master HaKu 阅读(1500) 评论(0) 推荐(0) 编辑

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