Where can I find data member of std::bitset?

Viewed 127

When I read the bitset page on cppreference, I tried to find some data memeber column to see how the data is stored. I found that there's no such column and neither another std class such as std:string. Then I go to https://github.com/llvm-mirror/libcxx/blob/master/include/bitset, check the bitset synopsis comment part, and there's nothing I can't find about its data member. Why? What do I miss here? An example of any std classes would be much appreciated.

2 Answers

CppReference documents the public interface, which is the only thing the standard mandates and that you are supposed to care about.

Same for the synopsis of the libc++ header: it's just a copy-paste from the standard, probably put there as a reference for the library implementors. You can find the nitty-gritty details of the implementation below.

Data members of STL containers are implementation details you are not supposed to care about and subject to change, both between the various standard libraries implementations, as well as for different versions of the same library or even different compilation flags.

Checking the libcxx implementation, The following protected data member is how the real bits are implemented.

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>
{ /* ... */ };
Related