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();
$ b $ p
$ b如果我们尝试使用结果,返回类型是 void
。
这是一些gcc扩展还是bug?
如果前者为真,它是做什么的?
解决方案我的 / usr / include / c ++ / 4.8 / bits / stl_bvector .h
有:
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// DR 464.对新建议成员函数在标准容器中。
// N.B. DR 464对矢量< bool>但由于我们在调试模式
// vector类中实现DR 464的方式,因此我们需要
//。
void
data()_GLIBCXX_NOEXCEPT {}
在 / usr / include / c ++ / 4.8 / debug / vector 我看到了声明:
using _base ::数据;
这似乎是原因:调试版本 std ::除非存在 std :: vector< bool> :: data
,否则vector< bool>
不会编译。
According to the standard, std::vector<bool>
has no member function data()
. However, the following snippet compiles fine with the latest GCC with libstdc++:
#include <vector>
int main () {
std::vector<bool> v;
v.data();
}
If we try to use the result, it turns out the return type is void
.
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:
// _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 { }
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.
这篇关于libstdc ++的std :: vector< bool> :: data有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!