libstdc++ 的 std::vector<bool>::data 有什么作用?
What does libstdc++'s std::vector<bool>::data do?
按照标准,std::vector<bool>
没有成员函数data()
。但是,以下代码片段可以在带有 libstdc++ 的最新 GCC 中正常编译:
#include <vector>
int main () {
std::vector<bool> v;
v.data();
}
如果我们尝试使用结果,结果 return 类型是 void
。
这是一些 gcc 扩展还是错误?
如果前者是真的,它有什么作用?
我的 /usr/include/c++/4.8/bits/stl_bvector.h
有:
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 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.
void
data() _GLIBCXX_NOEXCEPT { }
在/usr/include/c++/4.8/debug/vector
中我看到声明:
using _Base::data;
所以这似乎是原因:除非 std::vector<bool>::data
存在,否则 std::vector<bool>
的调试版本不会编译。
按照标准,std::vector<bool>
没有成员函数data()
。但是,以下代码片段可以在带有 libstdc++ 的最新 GCC 中正常编译:
#include <vector>
int main () {
std::vector<bool> v;
v.data();
}
如果我们尝试使用结果,结果 return 类型是 void
。
这是一些 gcc 扩展还是错误?
如果前者是真的,它有什么作用?
我的 /usr/include/c++/4.8/bits/stl_bvector.h
有:
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 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.
void
data() _GLIBCXX_NOEXCEPT { }
在/usr/include/c++/4.8/debug/vector
中我看到声明:
using _Base::data;
所以这似乎是原因:除非 std::vector<bool>::data
存在,否则 std::vector<bool>
的调试版本不会编译。