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

According to the standard, std::vector<bool> does not have a member function data() . However, the following code snippet compiles fine with the latest GCC using libstdc ++:

 #include <vector> int main () { std::vector<bool> v; v.data(); } 

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

Is this some kind of gcc extension or bug?
If the first is true, what is he doing?

+5
source share
1 answer

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

 // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 464. Suggestion for new member functions in standard containers. // NB 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. void data() _GLIBCXX_NOEXCEPT { } 

In /usr/include/c++/4.8/debug/vector I see an ad:

 using _Base::data; 

Thus, this could be the reason: the debug version of std::vector<bool> will not compile if std::vector<bool>::data does not exist.

+10
source

Source: https://habr.com/ru/post/1258729/


All Articles