V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wbingeek
V2EX  ›  问与答

在 c++中, bits 目录跟 tr1 目录的区别?

  •  
  •   wbingeek · 2015-06-02 19:36:58 +08:00 · 2161 次点击
    这是一个创建于 3302 天前的主题,其中的信息可能已经有所发展或是发生改变。
    刚知道原来map和unordered_map的实现方式不同,前者用的红黑树,后者用的哈希表

    所以就想看下系统中map和unordered_map源码的实现方式

    当我命令行中输入` find / | grep unordered_map` 时,出现了两个相同的文件:
    **
    /usr/include/c++/5.1.0/bits/unordered_map.h
    /usr/include/c++/5.1.0/tr1/unordered_map.h
    **
    分别放在bits和tr1目录中,然后就google下这两个目录的区别:

    这是stackoverflow上对bits目录的解释:

    >The official designation of that folder according to the libstdc++ documentation is:
    >
    >"Files included by standard headers and by other files in the bits directory"
    >Where "bits" probably just means something trivial as "the bits that make up the implementation of >what you include via the standard headers".

    >For example, if you include the standard <algorithm> header, you really include bits/c++config.h, >bits/stl_relops.h, bits/stl_pair.h bits/stl_algobase.h and bits/stl_algo.h under the hood, each of >which defines the odd bits that alltogether give you what someone including <algorithm> would >expect to get.

    Boost calls the conceptually same folder "detail".

    ====

    但是对于上面的解释,自己表示没怎么理解,所以想来这里问下各位!!!
    1 条回复    2015-06-02 20:28:18 +08:00
    comicfans44
        1
    comicfans44  
       2015-06-02 20:28:18 +08:00   ❤️ 1
    tr1(Technology Report 1)目录是允许直接包含的


    之前c++新标准讨论过程中,下一代c++标准还没有完成,但一部分内容已经形成一定共识,这部分库被单独放在tr1目录下。但是最终纳入下一代c++标准的结果与tr1时有所不同,unordered_map就变成两个了(你可以diff一下两个实现) 。如果你按照tr1的标准来使用unordered_map,就应该包含tr1/unordered_map。如果不考虑这个兼容性,那就应该使用最终的unordered_map



    bits目录不应该直接包含
    gcc的具体实现都放在了bits目录里面(也就是具体实现细节,和boost库的detail目录一样,都是库的编写者的内部实现,库的使用者不应该直接包含这些目录里面的文件)你包含的头文件会间接包含bits里面的文件
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   909 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 19:54 · PVG 03:54 · LAX 12:54 · JFK 15:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.