向量和维度vecotr本身具有特定的数据类型
vector and dimension vecotr with itself has a specific data type
我需要向量,boolean,std:string和int,我在谷歌上搜索并将多维向量定义为:
std::vector< std::vector< std::vector <std::vector<int> > > a;
但它对我来说有问题,它只有一种数据类型,我找到了一对:
std::vector<std::pair<bool,float> > a;
但是std::pair有问题,不能定义更多的二维。
问题:如何定义多维向量,每个维度都有特定的数据类型?注意:我需要三维。
template<typename First, typename Second, typename Third>
struct triplet
{
triplet()
{
}
triplet(const First& f, const Second& s, const Third& t):
first(f), second(s), third(t)
{
}
First first;
Second second;
Third third;
};
template<typename First, typename Second, typename Third>
triplet make_triplet(const First& f, const Second& s, const Third& t)
{
return triplet(f, s, t);
}
当然,如果您支持C++11,请使用std::tuple<Args...>
,如果可以使用boost但没有C++11支持,则使用boost::tuple
。
您可以使用std::tuple
std::vector<std::tuple<bool, std::string, int>>
但这并不是一个多方面的矢量。它是元组的线性向量。
如果std::pair
的唯一问题是缺少超过2个维度,则可以使用std::tuple
(c++11)或boost::tuple
的向量。或者只需创建自己的结构
一个同时包含值和向量的std::pair
怎么样?即
std::vector<std::pair<bool, std::vector<std::pair<std::string, str::vector<int>>>>>
怎么样:
struct mytype {
bool a;
std::string str;
int num;
};
std::vector<mytype>
相关文章:
- 防止主数据类型C++的隐式转换
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 在C++中打印指向不同基元数据类型的指针的内存地址
- C++浮点数据类型和字符串数据类型无法子到模板函数中
- 如何计算数据类型的范围,例如int
- C++中数据类型修饰符的顺序
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- 特定数据类型的模板类
- 具有多个模板的模板函数,用于特定数据类型(如字符串)?
- 有没有办法提示用户使用哪种数据类型作为模板 c++
- int数据类型的指针指向的是什么,如果是一个类的私有数据成员,我们创建了该类的两个对象?
- 时间复杂度 当具有复合数据类型(如元组或对)时?
- 如何获取C++字符数据类型的地址
- 将复杂的非基元C++数据类型转换为 Erlang/Elixir 格式,以使用 NIF 导出方法
- 构造智能点数据类型以及普通数据类型的通用方法
- 如何使映射键具有两种不同的数据类型?
- 数据类型"struct seq<0, 1, 2>{}"含义是什么?
- 如何在不破坏现有应用程序的情况下更改 API 中 stl 容器的数据类型?
- Static_cast转换为错误的数据类型,但结果仍然正确?
- 向量和维度vecotr本身具有特定的数据类型