// Filename:    stl_construct.h// Comment By:  凝霜
// E-mail:      mdl2009@vip.qq.com
// Blog:        http://blog.csdn.net/mdl13412/*** Copyright (c) 1994* Hewlett-Packard Company** Permission to use, copy, modify, distribute and sell this software* and its documentation for any purpose is hereby granted without fee,* provided that the above copyright notice appear in all copies and* that both that copyright notice and this permission notice appear* in supporting documentation.  Hewlett-Packard Company makes no* representations about the suitability of this software for any* purpose.  It is provided "as is" without express or implied warranty.*** Copyright (c) 1996,1997* Silicon Graphics Computer Systems, Inc.** Permission to use, copy, modify, distribute and sell this software* and its documentation for any purpose is hereby granted without fee,* provided that the above copyright notice appear in all copies and* that both that copyright notice and this permission notice appear* in supporting documentation.  Silicon Graphics makes no* representations about the suitability of this software for any* purpose.  It is provided "as is" without express or implied warranty.*//* NOTE: This is an internal header file, included by other STL headers.*   You should not attempt to use it directly.*/#ifndef __SGI_STL_INTERNAL_CONSTRUCT_H
#define __SGI_STL_INTERNAL_CONSTRUCT_H#include <new.h>        // 需要placement new的原型__STL_BEGIN_NAMESPACE// 调用成员的析构函数, 需要类型具有non-trivial destructor
template <class T>
inline void destroy(T* pointer)
{pointer->~T();
}// 使用placement new在已经分配的内存上构造对象
// 如果你不熟悉placement new, 请参考
// http://msdn.microsoft.com/en-us/library/kewsb8ba.aspx
// http://blogs.msdn.com/b/jaredpar/archive/
//        2007/10/16/c-new-operator-and-placement-new.aspx
template <class T1, class T2>
inline void construct(T1* p, const T2& value)
{new (p) T1(value);
}// 析构一组对象, 用于具有non-trivial destructor
template <class ForwardIterator>
inline void
__destroy_aux(ForwardIterator first, ForwardIterator last, __false_type)
{for ( ; first < last; ++first)destroy(&*first);
}// 如果没有类型non-trivial destructor, 则使用此函数
template <class ForwardIterator>
inline void __destroy_aux(ForwardIterator, ForwardIterator, __true_type) {}// 使用traits技术, 判断类型是否就有non-trivial destructor, 然后调用不同的函数
template <class ForwardIterator, class T>
inline void __destroy(ForwardIterator first, ForwardIterator last, T*)
{typedef typename __type_traits<T>::has_trivial_destructor trivial_destructor;__destroy_aux(first, last, trivial_destructor());
}// 用于销毁一组对象//                                                char *特化版本
//                                               ---------- destroy不进行析构
//                                               |
// destroy(first, last) -------------------------- 特化
//                                   |           |
//                                   |  泛化     ----------- destroy不进行析构
//                                   |           wchar_t *特化版本
//                                   ↓
//                调用 __destroy(first, last, value_type(first));
//                根据是否具有trivial destructor进行函数转发
//                                   |
//                                   |---------------- has trivial destructor?
//                                   |
//               -------------------------------------------
//        No     |                                         | Yes
//               |                                         |
//               ↓                                         ↓
// __destroy_aux(..., __true_type)           __destroy_aux(..., __false_type)
// 不进需要行析构操作                          for ( ; first < last; ++first)
//                                              destroy(&*first);template <class ForwardIterator>
inline void destroy(ForwardIterator first, ForwardIterator last)
{__destroy(first, last, value_type(first));
}// 特化版本
inline void destroy(char*, char*) {}
inline void destroy(wchar_t*, wchar_t*) {}__STL_END_NAMESPACE#endif /* __SGI_STL_INTERNAL_CONSTRUCT_H */// Local Variables:
// mode:C++
// End:

《STL源码剖析》-- stl_construct.h相关推荐

  1. 《STL源码剖析》笔记——allocator

    六大组件间关系 部分STL文件包含关系 allocator包含于中: 实际实现于三个文件 : 1.stl_construct.h :对象的构造和析构 2.stl_alloc.h空间配置和释放 3.st ...

  2. 《STL源码剖析》学习-- 1.9-- 可能令你困惑的C++语法1

    最近在看侯捷的<STL源码剖析>,虽然感觉自己c++看得比较深一点,还是感觉还多东西不是那么明白,这里将一些细小的东西或者概念记录一下. 有些东西是根据<C++编程思想>理解的 ...

  3. STL源码剖析——P142关于list::sort函数

    在list容器中,由于容器自身组织数据的特殊性,所以list提供了自己的排序函数list::sort, 并且实现得相当巧妙,不过<STL源码剖析>的原文中,我有些许疑问,对于该排序算法,侯 ...

  4. STL源码剖析 stack 栈 概述->(使用deque双端队列 / list链表)作为stack的底层容器

    Stack是一种先进后出的数据结构,他只有一个出口 stack允许 新增元素.移除元素.取得最顶端的元素,但是无法获得stack的内部数据,因此satck没有遍历行为 Stack定义的完整列表 (双端 ...

  5. STL源码剖析 __type_traits

    traits编程 弥补了C++本身的不足 STL只对迭代器进行规范制定出了iterator_traits,SGI在此基础上进一步扩展,产生了__type_traits 双下划线的含义是这个是SGI内部 ...

  6. STL源码剖析 空间配置器 查漏补缺

    ptrdiff_t含义 减去两个指针的结果的带符号整数类型 ptrdiff_t (Type support) - C 中文开发手册 - 开发者手册 - 云+社区 - 腾讯云 std::set_new_ ...

  7. STL源码剖析之配接器

    adapter(配接器)在STL组件的灵活组合运用上,扮演者转换器的角色.adapter来源于一种适配器模式,其功能是:将一个class接口转换为另一个class的接口,使得原本因接口不兼容而不能合作 ...

  8. 【STL源码剖析】list模拟实现 | 适配器实现反向迭代器【超详细的底层算法解释】

    今天博主继续带来STL源码剖析专栏的第三篇博客了! 今天带来list的模拟实现! 话不多说,直接进入我们今天的内容! 前言 那么这里博主先安利一下一些干货满满的专栏啦! 手撕数据结构https://b ...

  9. STL(C++标准库,体系结构及其内核分析)(STL源码剖析)(更新完毕)

    文章目录 介绍 Level 0:使用C++标准库 0 STL六大部件 0.1 六大部件之间的关系 0.2 复杂度 0.3 容器是前闭后开(左闭右开)区间 1 容器的结构与分类 1.1 使用容器Arra ...

  10. STL源码剖析学习七:stack和queue

    STL源码剖析学习七:stack和queue stack是一种先进后出的数据结构,只有一个出口. 允许新增.删除.获取最顶端的元素,没有任何办法可以存取其他元素,不允许有遍历行为. 缺省情况下用deq ...

最新文章

  1. 想学python都要下载什么软件-学编程闲余时间建议下载的软件_Python新手入门教程...
  2. NOIP2017洛谷P3953:逛公园(分层图最短路、dp、拓扑)
  3. 解决: service endpoint with name xxx already exists ( docker 已删除的容器却依旧存在)
  4. 双硬盘奇怪问题...
  5. python和c++无缝对接_总结:Python学习 和 Python与C/C++交互
  6. java多态的两种形式_java核心(八):继承与方法重写、final、多态性的两种描述形式...
  7. Tosca 添加 modules,添加Library,引用重复步骤
  8. python在线编程免费课程-Python少儿基础编程课程
  9. Codeforces Round #518 (Div. 2): E. Multihedgehog(模拟)
  10. 使用zk可以实现Master选举,实现原理是什么?
  11. 寻找圣杯 In Search of the Holy Grail
  12. RedHat Enterprise Linux 5下安装firefox
  13. python获取灰度图边界
  14. C#多个DataTable根据某一列匹配,其余字段相加求和的高效算法。
  15. offer收割者!Alibaba内部独家MySQL优化宝典横空出世,再也不用担心被面试官拦路了
  16. 耐心看完,越到后面越精彩
  17. 使用java进行pdf转word实战
  18. mtk6595资料帖和问题帖集合
  19. 人人都能当“苍天哥” 手把手教你制作游戏视频
  20. (转)Lua之父采访记录

热门文章

  1. 【C语言】取余%操作在编程中的重要作
  2. 微信小程序下载文件至本地,并打开文档
  3. Android系统功耗优化之CPU - CPU功耗和频率的关系
  4. 七彩虹平板刷成android,大功告成 七彩虹G808首个MIUI ROM移植
  5. ENC28J60学习
  6. android实现热更新
  7. 最窄770px最宽1024px的经典布局研究
  8. CSS Sprites(精灵图)
  9. 遇到mysqladmin flush-hosts报错解决思路
  10. ncl如何添加线shp文件_NCL画图个例讲解.pdf