代码之家  ›  专栏  ›  技术社区  ›  Rick Jim DeLaHunt

在哪里可以找到std::bitset的数据成员?

c++
  •  3
  • Rick Jim DeLaHunt  · 技术社区  · 7 年前

    当我读到 bitset page 我试着找到一些 列以查看数据的存储方式。我发现没有这样的专栏,也没有像这样的std类 std:string . 那我就去 https://github.com/llvm-mirror/libcxx/blob/master/include/bitset ,检查

    2 回复  |  直到 7 年前
        1
  •  4
  •   amin    7 年前

    在检查libcxx实现时,下面的受保护数据成员是如何实现实位的。

    https://github.com/llvm-mirror/libcxx/blob/master/include/bitset#L163

    template <size_t _N_words, size_t _Size>
    class __bitset {
    public:
      typedef size_t __storage_type;
      // ...
    protected:
      // ...
      __storage_type __first_[_N_words]; // <========= the data
    };
    
    // ...
    
    template <size_t _Size>
    class _LIBCPP_TEMPLATE_VIS bitset
        : private __bitset<
              _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
    { /* ... */ };
    
        2
  •  7
  •   Matteo Italia    7 年前

    CppReference记录了公共接口,这是标准要求的唯一内容,也是您应该关心的。

    libc++头的概要也一样:它只是标准的一个拷贝粘贴,可能作为库实现者的参考。您可以在下面找到实现的基本细节。