How to store a bit-array in C++?(如何在 C++ 中存储位数组?)
问题描述
在 C++ 中存储位数组的最佳方式是什么(没有 Boost,只有标准容器),例如表示卷分配位图?
What's the best way to store a bit array in C++ (no Boost, just standard containers), representing, for example, a volume allocation bitmap?
我认为 std::vector<bool> 是个好主意,但 显然它是邪恶的并且已被弃用,那么有更好的选择吗?
I thought std::vector<bool> was a great idea, but apparently it's Evil and deprecated, so is there a better choice?
如果我在内存中有一个字节数组,我将如何将它们复制到推荐的容器中?
(我无法为 vector<bool> 弄清楚这一点.)
If I have a byte array in memory, how would I go about copying them to the recommended container?
(I'm having trouble figuring this out for vector<bool>.)
推荐答案
6 年后才发这个给后人:就像其中一位评论者所说,我得出的结论是 完全没问题使用 std::vector<bool> 作为它自己的特殊类型.唯一需要注意的是不要将其视为标准 bool 容器,因为它不是.
Just posting this 6 years later for posterity: like one of the commenters said, I came to the conclusion that it's perfectly fine to use std::vector<bool> as its own specialized type. The only thing you need to be careful of is not to treat it like a standard bool container, since it isn't.
这篇关于如何在 C++ 中存储位数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 C++ 中存储位数组?
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
