将 std::vector<bool> 添加到容器的变体中
Adding std::vector<bool> to a Variant of Containers
我正在包装一个C接口,它有一个加载函数返回一个Value*
对象,它指向Value
对象的动态数组:
typedef struct Value {
union {
int8_t i8;
int16_t i16;
int32_t i32;
int64_t i64;
bool b;
} value;
} Value_T;
给定数组中的对象总是同一类型。
我的想法是在c++中这样表示:
typedef boost::variant<std::vector<bool>, std::vector<int8_t>, std::vector<int16_t>, std::vector<int32_t>, std::vector<int64_t>, std::vector<std::string> > Container;
这是合理的吗?我应该注意哪些陷阱?是否有编译器特定的问题,关于如何定义bool ?我意识到std::vector在内部是用位表示的,这方面还有其他问题。
我正在使用c++ 98编译器
既然你已经在使用Boost,最好只使用boost::containers::vector<bool>
。这个容器会有你想要的行为
boost::variant
是类型无关的,无论std::vector<bool>
实现的细节如何,它都应该工作。
相关文章:
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中用vector填充一个简单的动态数组
- vector.resize()中的分配错误
- 使用std::vector的OpenCL矩阵乘法
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 在某些循环内使用vector.push_back时出现分段错误
- 当vector是tje全局变量时,c++中vector的内存管理
- std::vector的包装器,使数组的结构看起来像结构的数组
- 为什么(-1)%vector::size()总是返回0
- 在C++中将类(带有Vector成员)保存为二进制文件
- 编译器如何区分std::vector的构造函数
- 将 int 数组转换为 std::vector<int*>
- 使用 pqxx 将 std::vector 存储在 postgresql 中,并从数据库中检索它
- EASTL矢量<向量<int>>连续的
- 在std::vector上存储带有模板的类实例
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- 使用 std::vector<boost::shared_ptr<Base_Class>> 或 boost::p tr_vector 的性能注意事项是什么<Base>
- 将矩阵"shared_ptr<vector<vector>sp"的行"(*sp)[i]"<T>传递给接受"shared_ptr<vector<T>>
- 如何获取std::vector<DMatch>