C++中bitset很方便的实现了位操作,有几点需要注意,可以参考源代码:
https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.2/bitset-source.html
它的模板是
00645 template<size_t _Nb>
00646 class bitset
00647 : private _Base_bitset<_GLIBCXX_BITSET_WORDS(_Nb)>size_t 是在编译时候就已经得到了,然后将_Nb除上每个大小得到_Nw,_Nw即为模板泛化得到的首地址:
00077 template<size_t _Nw>
00078 struct _Base_bitset
00079 {
00080 typedef unsigned long _WordT;
00081
00082 /// 0 is the least significant word.
00083 _WordT _M_w[_Nw];因此,bitset不需要像vector一样存一个首地址。。。

本文深入探讨了C++中bitset的使用方法及其背后的实现机制,通过官方文档链接展示其模板化设计和内存管理策略,强调了bitset在位操作方面的优势和应用场景。
2004

被折叠的 条评论
为什么被折叠?



