SGI STL源码
文章平均质量分 73
yafeng_jiang
这个作者很懒,什么都没留下…
展开
-
一个简单的空间配置器: allocator
这个简单实现类中的方法主要是有allocate()deallocate()construct()destroy()实际在SGI STL中construct()和destroy()是以全局函数的方式出现的~~//jjalloc.h#ifndef JJALLOC_H#define JJALLOC_H#include //for placement new#includ原创 2011-11-18 14:56:59 · 1550 阅读 · 0 评论 -
vector实现
vector实现:程序在windows xp下vs2010中编译通过。//vector.h#ifndef VECTOR_H#define VECTOR_H#include #include #include "construct.h"using std::allocator;template >class vector {public: //vector原创 2011-11-22 19:12:38 · 4026 阅读 · 0 评论 -
内积算法inner_product
函数模板://iner_product.h#ifndef INNER_PRODUCT_H#define INNER_PRODUCT_H//版本1template T inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init) { for( ; first1原创 2011-12-06 10:39:10 · 5120 阅读 · 0 评论 -
accumulate算法
accumulate主要用于元素累加算法模板//accumulate.htemplate T accumulate(InputIterator first, InputIterator last, T init) { for( ; first != last; ++first) { init = init + *first; } return init;}templ原创 2011-11-17 15:07:09 · 1235 阅读 · 0 评论 -
构造和析构函数construct(), destroy()
SGI STL中 构造函数 construct 和 destroy() 都是全局函数//construct.h#ifndef CONSTRUCT_H#define CONSTRUCT_H#include #include "type_traits.h"#include "iterator.h"template inline void construct(T1原创 2011-11-19 21:01:30 · 2511 阅读 · 0 评论 -
find泛型算法
学习stl有段时间了,总想写点什么,做点笔记,然后就开始纠结了是先写allocator, vector还是别的,最终决定柿子先挑软的捏,从算法开始吧,此为我的第一作,呵呵.一个比较简单的find算法,先声明不是容器内部的算法,是一个泛型算法~~在此先向>这本书致敬!-------------------------------------------------------原创 2011-11-17 14:56:14 · 3038 阅读 · 0 评论 -
类型萃取器__type_traits
//type_traits.h#ifndef TYPE_TRAITS_H#define TYPE_TRAITS_Hstruct __true_type {};struct __false_type {};template struct __type_traits { //不要移除 typedef __true_type this_dummy_member_must_be_fir原创 2011-11-19 21:03:22 · 2069 阅读 · 0 评论 -
STL中的空间配置器
SGI STL分为两级空间配置器:以下代码展现了alloc中内存的调度//alloc.h#ifndef ALLOC_H#define ALLOC_H#if 0# include # define __THROW_BAD_ALLOC throw bad_alloc#elif !defined(__THROW_BAD_ALLOC)# include # define __原创 2011-11-19 21:14:55 · 1858 阅读 · 0 评论 -
adjacent_difference算法
adjacent_difference算法的主要用途是计算相邻元素的差额函数模板//adjacent_difference.htemplate OutputIterator adjacent_difference(InputIterator first, InputIterator last, OutputIterator result) { if(first == last原创 2011-11-18 10:07:24 · 2777 阅读 · 0 评论 -
迭代器
//iterator.h#ifndef ITERATOR_H#define ITERATOR_H//五种迭代器类型struct input_iterator_tag {};struct output_iterator_tag {};struct forward_iterator_tag: public ::input_iterator_tag {};struct bidirecti原创 2011-11-19 21:06:04 · 1113 阅读 · 0 评论