zoukankan      html  css  js  c++  java
  • STL Allocator

    rebind

    from: http://topic.csdn.net/u/20080226/04/d3187cbf-c72e-4f29-b6f0-ed05e1f65f95.html

    rebind的本质应该这么说:给定了类型T的分配器Allocator=allocator<T>,现在想根据相同的策略得到另外一个类型U的分配器allocator<U>,那么allocator<U> = allocator<T>::Rebind<U>::other.
    之所以要提供rebind界面,是因为容器只知道模板参数名Allocator,而不是其具体实现,容器只知道这样三个事情:
    1、Alocator是T的分配器,但其内部实现策略是什么容器并不关心(可能是std::allocator<T>,也可能是myallocator<T>)。换句话说,容器并不知道allocator模板名。
    2、类型T和类型U在逻辑上是相关的,比如在链表中,数据类型T和结点类型Node<T>是有联系的。
    3、容器希望按照和T一样的策略(具体的说就是相同的allocator模板名)来分配U类型的对象。
    这时rebind的作用就体现出来了,标准中规定
    对一个allocator<T>,和一个类型U,必须有allotor<T>::rebind<U>::other=allocator<U>,这样容器就可以得到U的分配器,也就是说,rebind的本质应该是:,
    对allotor<T>::rebind<U>,T和U的分配器必须是同一个模板名。这个模板可以是std::allocator,也可以是用户自定义的分配器模板Myallocator,自然,为了使自己的分配器可以作为容器的模板参数,Myallocator中也必须定义rebind成员,且其实现必为
    template<typename U>
    rebind{
    typedef Myallocator<U> other;
    };
    因此,同族的分配器指的是具有相同模板名的一组分配器。
    如std::allcoator<T>和std::allcoator<U>是同族的,你可以把std::allcoator<T>::rebind<U>::other看成std::allcoator<U>。Myallocator<T>和Myallocator<U>是同族的,你可以把Myallcoator<T>::rebind<U>::other看成Myallcoator<U>。但allcoator<T>和Myallocator<U>就不是同族的。

  • 相关阅读:
    向SDE库中写入栅格和矢量数据
    datagridview使用方法
    GP Statics
    GP tool , Resample, Mask, Clip
    好的影像库网站
    文件及文件夹相关操作
    使用GeoProcessing进行批处理的编程方式(粗粒度的编程)
    git clear local branches All In One
    node js module exports multiple variables All In One
    推荐的 iPad 绘画入门教程资源 All In One
  • 原文地址:https://www.cnblogs.com/whyandinside/p/1779839.html
Copyright © 2011-2022 走看看