C++ bitset的实现

来源:互联网 发布:淘宝网旋转拖把杆 编辑:程序博客网 时间:2024/06/15 15:58

C++中bitset很方便的实现了位操作,有几点需要注意,可以参考源代码:

https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.2/bitset-source.html


它的模板是

00645   template<size_t _Nb>00646     class bitset00647     : private _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)>

size_t 是在编译时候就已经得到了,然后将_Nb除上每个大小得到_Nw,_Nw即为模板泛化得到的首地址:

00077   template<size_t _Nw>00078     struct _Base_bitset00079     {00080       typedef unsigned long _WordT;00081 00082       /// 0 is the least significant word.00083       _WordT        _M_w[_Nw];

因此,bitset不需要像vector一样存一个首地址。。。

0 0