stl_construct.h
// 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 02:构造析构的基本工具construct()和destroy()(stl_construct.h)

    一.前言 上一篇,我先完成了对内存配置器的实现.然而后面在内存上的算法还依赖于两个全局函数,construct()和destroy(),前者负责在指定的内存上调用对象的构造函数,在内存上构造出对象.后 ...

  2. STL stl_config.h

    stl_config.h . // Filename: stl_config.h . . // Comment By: 凝霜 . // E-mail: mdl2009@vip.qq.com . // ...

  3. STL defalloc.h

    defalloc.h . // Filename: defalloc.h . . // Comment By: 凝霜 . // E-mail: mdl2009@vip.qq.com . // Blog ...

  4. STL stl_alloc.h

    # // Comment By: 凝霜 # // E-mail: mdl2009@vip.qq.com # // Blog: http://blog.csdn.net/mdl13412 # # // ...

  5. STL stl_uninitialized.h

    stl_uninitialized.h // Filename: stl_uninitialized.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com ...

  6. STL源代码剖析 容器 stl_hashtable.h

    本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie hashtable ------------------------------------ ...

  7. STL库的内存配置器(allocator)

    正在学习中,如果有错,还请多多指教,根据不断的理解,会进行更改,更改之前的样子都会保留下来,记录错误是最大的进步,嗯嗯! 具有次配置力的SGI空间配置器(SGI是STL的一种版本,也有其他的版本) 这 ...

  8. STL六大组件之——分配器(内存分配,好深奥的东西)

    SGI设计了双层级配置器,第一级配置器直接使用malloc()和free(),第二级配置器则视情况采用不同的策略:当配置区块超过128bytes时,视之为“足够大”,便调用第一级配置器:当配置区小于1 ...

  9. STL源码剖析读书笔记--第四章--序列式容器

    1.什么是序列式容器?什么是关联式容器? 书上给出的解释是,序列式容器中的元素是可序的(可理解为可以按序索引,不管这个索引是像数组一样的随机索引,还是像链表一样的顺序索引),但是元素值在索引顺序的方向 ...

随机推荐

  1. E - What Is Your Grade?

    E - What Is Your Grade? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  2. 【Emit】关于System.MethodAccessException解决方案

        最近学习Emit,在使用Emit动态生成对象时碰到一些"蛋疼"的问题,如下: 1.安全透明方法"XXX.XX()"尝试访问安全关键方法"YYY ...

  3. A norm is a function. 范数是函数。

    [范数]范数是函数.A norm is a function.范数(norm),是具有“长度”概念的函数.在线性代数.泛函分析及相关的数学领域,是一个函数,其为向量空间内的所有向量赋予非零的正长度或大 ...

  4. c#的const可以用于引用类型吗

    答案是可以的.不过用const修饰的类实例只能是null. class A{ public int a=0; } class B{ const A constA=null; const object ...

  5. Linux中rpm包管理器

    包全名: 1.操作的包是没有安装的软件包时,使用全名,而且要注意路径 2.例如:jdk-8u131-linux-x64.rpm包名: 1.操作的是已经安装好的软件包,使用包名,是搜索/var/lib/ ...

  6. CentOS7安装MySQL8.0小计

    之前讲配置文件和权限的时候有很多MySQL8的知识,有同志说安装不太一样,希望发个文,我这边简单演示一下 1.环境安装 下载MySQL提供的CentOS7的yum源 官方文档:<https:// ...

  7. You are using pip version 8.1.2, however version 9.0.1 is available.

    [root@localhost ~]# pip install virtualenvmapperCollecting virtualenvmapper  Could not find a versio ...

  8. client = new DatagramSocket(LocalPort) 是说端口已经被占用的意思

    ok 现在遇到一个问题,client = new DatagramSocket(LocalPort) 是说端口已经被占用的意思 ref:!!https://community.oracle.com/t ...

  9. Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times

    http://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-tha ...

  10. DEV开发之界面皮肤

    最终效果:正文本人的环境是 VS2013+DEV 13.21.第一步,新建项目,(忽略)???2.修改Form1.cs的基类,Form修改为DevExpress.XtraBars.Ribbon.Rib ...