
C and C++
iteye_16355
这个作者很懒,什么都没留下…
展开
-
一个STL风格的动态二维数组
#ifndef __KIMI_BOOST_ARRAY2#define __KIMI_BOOST_ARRAY2#pragma once#include <cstddef> //size_t#include <exception>//exception#include <iterator>//random_access_iterator_tag,reverse_...2007-07-22 18:05:00 · 153 阅读 · 0 评论 -
C++ Meta Programming 和 Boost MPL(3)
本系列全部转载自kuibyshev.bokee.com1. 模板元编程的基本用途1.1. 数值计算上文提及的所有关于模板元编程的例子都是在编译时的数值计算,这是模板元编程的最简单直接的使用方法。数值计算主要利用模板的特化和局部特化能力进行递归演算,模板类被视为元函数,利用类中的一个静态常量保存结果。由于C++模板对非类型的参数有限制,一般只有整型和布尔型可以参加运算。元...2007-08-30 23:06:00 · 115 阅读 · 0 评论 -
C++ Meta Programming 和 Boost MPL(4)
本系列全部转载自kuibyshev.bokee.com1. Boost中的MPL库分析MPL是由David Abrahams和Aleksey Gurtovoy为方便模板元编程而开发的库,2003年被Boost吸纳为其中的一员,此后又历经一些大幅度修改,目前已经相当完善,其最新版本于2004年11月发布。MPL的出现是C++模板元编程发展中的一大创举,它提供了一个通用、高层次...2007-08-30 23:07:00 · 186 阅读 · 0 评论 -
泛型归并排序
#define SENTINEL_CARD (-1)#include <vector>#include <algorithm>#include <iterator>#include <functional>#include <iterator> template< class bidirect...2007-09-18 00:23:00 · 156 阅读 · 0 评论 -
泛型插入排序
#pragma once#include <iterator>#include <functional> template< class bidirectional_iterator, template<class> class greater_compare = std::greater > class ins...2007-09-18 00:25:00 · 186 阅读 · 0 评论 -
boost.tuple源码整理和使用说明
IntroductionA tuple (or n-tuple) is a fixed size collection of elements. Pairs, triples, quadruples etc. are tuples. In a programming language, a tuple is a data object containing other objects as e...2007-10-07 23:13:00 · 158 阅读 · 0 评论 -
在VS2005中使用IBM Purify的注意事项
[b]Rational Purify 使用及分析实例可以见这里[/b]http://www.ibm.com/developerworks/cn/rational/r-cail但是如果使用VC7,8,9的默认编译和链接设置,那是肯定找不到准确的错误位置的。为此,需要在VC8(VC7和VC9类似)中一些编译和链接参数要修改如下:Debug Information Format - Pr...2009-05-12 12:24:54 · 159 阅读 · 0 评论 -
C++编译器何时提供默认的构造函数和拷贝构造函数
2008年08月27日 星期三 10:16总的来说,编译器只在它需要的时候才会合成一个默认构造函数,或者扩张所有已存在的构造函数。一个类满足下列其中任何一个条件:1.包含了一个类的对象,这个对象有一个构造函数(包括编译器合成的默认构造函数)2.如果继承自一些基类,其中某些基类有一个构造函数(包括编译器合成的默认构造函数)3.有一个虚函数,或者继承到了虚函数4.有虚基...2008-12-07 11:32:01 · 361 阅读 · 0 评论 -
volatile的意义
2008年09月21日 星期日 20:14对于程序员就是variables that are changing or changed对于编译器就是禁止把变量放在寄存器中优化,每次都从内存中读取数据就这么简单...2008-12-07 11:32:25 · 223 阅读 · 0 评论 -
time_t的问题
2008年05月26日 星期一 12:29今天一上午调了一个网络程序,数据包中带有时间戳,我是用time_t来表示的client用的是winxp + vc8server用的是linux + gcc总是在包的持久化和反持久化出问题,原因在于:gcc中typedef long time_t;vc中typedef __int64 time_...2008-12-07 11:34:22 · 246 阅读 · 0 评论 -
C++ Meta Programming 和 Boost MPL(2)
本系列全部转载自kuibyshev.bokee.com1. 模板元编程的原理1.1. 函数式编程1.1.1. 函数式编程的概念从上面的例子可以看出,由于模板元编程借助的是C++模板的特化能力,使它的设计方法迥异于普通的C++编程习惯。比如我们不能够在元函数中使用变量,编译期显然只可能接受静态定义的常量,也就因此,我们不能够使用传统意义上的循环;要实现任何分支...2007-08-30 23:02:00 · 148 阅读 · 0 评论 -
C++ Meta Programming 和 Boost MPL(1)
本系列全部转载自kuibyshev.bokee.com1. 引论C++的发展史是一个不断吸收程序设计领域精华和不断积累充实语言特性的过程。它的创造者Stroustrup在这门新的编程语言草创之初就定下了几个基本的目标,二十年过去了,至今这些目标仍然是C++继续发展的指南针。其中他明确指出,这种语言不应强迫程序员使用单一程序设计形式[20];就是说C++语言应该是一种“多种花...2007-08-30 23:01:00 · 143 阅读 · 0 评论 -
泛型快速排序
Source#ifndef kimi_quicksort#define kimi_quicksort#include <functional>#include <iterator>#include <algorithm>namespace kimi_boost{using namespace std;tem...2007-08-28 03:20:00 · 117 阅读 · 0 评论 -
A wrong usage of boost.enable_shared_from_this
A wrong program in boost-user mail list:[code="C++"]#include #include #include #include // Inheritance Layout//// boost::enable_shared_from_this// ^// |// Base --------> ...2009-03-14 14:59:04 · 112 阅读 · 0 评论 -
才发现VC中也可以检测内存泄漏
[code="c++"]#include #define _CRTDBG_MAP_ALLOC#include #include #ifdef __cplusplus#ifdef DEBUG_NEW#undef DEBUG_NEW#endif#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)...2009-03-30 14:54:38 · 131 阅读 · 0 评论 -
boost.any源码整理和使用说明
Source#include <algorithm>#include <typeinfo>#include "boost/config.hpp"#include <boost/type_traits/remove_reference.hpp>#include <boost/type_traits/is_reference.hpp&g...2007-08-24 22:44:00 · 117 阅读 · 0 评论 -
boost.array源码整理和使用说明
Source#include <cstddef>#include <stdexcept>#include <boost/assert.hpp>// Handles broken standard libraries better than <iterator>#include <boost/detail/iterator...2007-08-24 22:45:00 · 125 阅读 · 0 评论 -
boost.BOOST_STATIC_ASSERT源码整理和使用说明
Source#include <boost/config.hpp>#include <boost/detail/workaround.hpp>//namespace kimi_boost{ //这个模板类只有声明,没有定义 //注意:这里没有{} //所以如果定义这个类型的对象将会失败 template <bool> st...2007-08-24 22:49:00 · 143 阅读 · 0 评论 -
boost.shared_ptr源码整理和使用说明
Source#pragma once//shared_ptr的简单实现版本//基于引用记数的智能指针//它可以和stl容器完美的配合namespace kimi_boost{template<class T> class shared_ptr{public: typedef T element_type; typedef T va...2007-08-24 22:51:00 · 145 阅读 · 0 评论 -
boost.lexical_cast源码整理和使用说明
Source#include <cstddef>#include <string>#include <typeinfo>//#include <boost/config.hpp>#include <boost/limits.hpp>#include <boost/throw_exception.hpp>...2007-08-24 22:55:00 · 162 阅读 · 0 评论 -
编译期判断类的继承性
介绍一个雕虫小技:编译期判断类的继承性。具体来说就是类型U是否继承自类型T。该技术的灵感和源头来自Andrei Alexandrescue的《Modern C++ Design》。原书中描述的此技术有一个小小的bug。源代码template <class T , class U>class __conversion{ static char test(U); s...2007-08-24 23:00:00 · 127 阅读 · 0 评论 -
boost.type_traits源码整理和使用说明(1)
IntroductionThe Boost type-traits library contains a set of very specific traits classes, each of which encapsulate a single trait from the C++ type system; for example, is a type a pointer or a ref...2007-08-28 01:35:00 · 125 阅读 · 0 评论 -
The Elements of Programing Style
把代码写清楚,别耍小聪明。想干什么,讲的简单点、直接点。只要有可能,使用库函数。避免使用太多的临时变量。“效率”不是牺牲清晰性的理由。让机器去干那些脏活。重复的表达式应该换成函数调用。加上括号、避免歧义。不要使用含糊不清的变量名。把不必要的分支去掉。使用语言的好特性,不要使用那些糟糕的特性。该用逻辑表达式的时候,不要使用过多的条件分支。如果逻辑表达式...原创 2009-08-09 18:26:23 · 199 阅读 · 0 评论