- 博客(12)
- 收藏
- 关注
原创 DiskDefrag: the problem
Problem StatementWhen files are stored on a hard disk, they often become fragmented. This means that the file is not stored in sequential sectors on the disk. The first half of a file might be stored
2005-08-22 10:14:00 1007
原创 SimpleRouter: the problem
Problem StatementA routers job is to route packets of information to the correct computer. In addition, a router may throw out some packets, or handle the packets on its own. In this problem, you are
2005-08-22 10:12:00 901
原创 TopCoder challenge: SimpleRouter --- Reloaded
This is the refactored version of SimpleRouter. By using boost.tokenizer, the parsing of rules and packets get simplified. By using polymophic and boost ptr_container, adding new types of rules get mu
2005-08-21 19:16:00 1004
原创 TopCoder challenge: SimpleRouter
This implementation is by no means elegant: it does not handle error well; it uses the same space for a forward table with a rule table; it uses hand-coded parsing, which is hard to read and modify...
2005-08-21 00:37:00 1058
原创 regex_test.cpp -- learning boost.regex
boost.regex 库的用法,看来这可能是 boost 当中写法最“常规”的库之一了。regex_test.cpp:#include #include #include #include #include using namespace std;// purpose:// takes the contents of a file in the form of a string// and se
2005-08-20 21:17:00 1084
原创 boost 智能指针 --- 关于性能的少数派报告
开门见山好了,boost 1.33 对于 boost 1.32 的 shared_ptr 和 weak_ptr 有一个不小的改变,然而这个改变如此透明,以至于它甚至于没有出现在 boost 1.33 的 release notes 中。在 1.32 中,shared_ptr 和 weak_ptr 的引用计数使用锁来保证线程安全,下面一段摘自 boost 1.32 的 sp_counted_bas
2005-08-18 23:15:00 4097 5
原创 泛型算法:Tips (4) --- 再论初始化
总有一些时候,我们不能够借助于“生成式”的初始化方法来给容器赋值,例如我们已经有了一个数组,要把它作为初值赋给一个容器,常规的做法已经深入人心了: int init[] = {2, 3, 5, 7, 11, 13, 17, 19, 23}; std::vector vect(init, init + sizeof(init)/sizeof(int));通过两个 sizeof 来得到数组的大小在
2005-08-16 23:11:00 1018 1
原创 8月11日的 Boost 1.33,bind 库存在的问题
问题的起因很简单,我实验一个简单的程序不过。这个程序的本意是想检验一下 boost.bind 在 1.33 中新加入的比较运算符,我以为这一点也不难,然而程序的运行结果大出我的意料:#include #include #include #include //#include //#include #include //using namespace boost::lambda;using name
2005-08-16 10:07:00 1242 4
原创 泛型算法:Tips (3) --- 初始化
上次提到过为容器生成数据的问题,我给出的用 boost.lambda 的方法是: std::vector vect(10); int i = 0; std::for_each( vect.begin(), vect.end(), _1 = ++var(i) );不错,这样可以生成连续的数字,也还算比较简洁,因为代码量不会随着容器的大小而变化,不过,如果要在容器内填入随机数呢?其实比上面更简单
2005-08-15 23:47:00 1245
原创 泛型算法:Tips (2) --- 累加
如果你想要把一个容器内的所有元素累加起来,应该怎么办?STL 的 accumulate 可以让我们不必自己写循环:#include #include #include #include #include int main(){ std::vector vect; vect.push_back(1); vect.push_back(2); vect.push_back(3); vect.p
2005-08-14 21:44:00 1514 1
原创 泛型算法:Tips (1) --- bind 基础
从 STL 出现到现在已经这么多年了,泛型算法是它的重要组成,也是其中最“看起来很美”的东西之一。然而在真实的程序设计中,它往往成为程序员的心头一痛,因为一旦要用 for_each ,accumulate 之类的算法做一些稍微复杂一点的事情,你就会发现自己一个头变成两个大。即便是有了 boost::bind 和 boost.lambda 的帮助,事情也仍然是扑朔迷离,求助于 comp.lang.c
2005-08-13 23:56:00 2183 5
原创 关于 Boost.Lambda
Boost.Lambda 的确是一个好东西,用来举例最多的恐怕就是这个了:using namespace boost::lambda;std::vector v;// init valuesstd::for_each(v.begin(), v.end(), std::cout 精致、优雅、易于理解,下面是一个更漂亮的例子:std::map values;// init valuesstd::for
2005-08-11 15:37:00 1438
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人