Baum mit Augen Baum mit Augen - 6 months ago 30
C++ Question

What does libstdc++'s std::vector<bool>::data do?

According to the standard,

has no member function
. However, the following snippet compiles fine with the latest GCC with libstdc++:

#include <vector>

int main () {
std::vector<bool> v;;

If we try to use the result, it turns out the return type is

Is this some gcc extension or a bug?

If the former is true, what does it do?


My /usr/include/c++/4.8/bits/stl_bvector.h has:

// DR 464. Suggestion for new member functions in standard containers.
// N.B. DR 464 says nothing about vector<bool> but we need something
// here due to the way we are implementing DR 464 in the debug-mode
// vector class.

In /usr/include/c++/4.8/debug/vector I see the declaration:

using _Base::data;

So that seems to be the reason: the debug version of std::vector<bool> wouldn't compile unless std::vector<bool>::data existed.