C++语法将ColorA拆分为浮点
C++ Syntax Split ColorA into floats?
我记得我能做这样的事情,但我不记得是怎么做的。我想从ColorA数据类型中提取浮点,在C++中最短的语法是什么?
ColorA(r,g,b,a)=material.getAmbient();
如果您愿意提供to_tuple
函数,可以在此处使用std::tie
。元组转换函数有一个更糟糕的解决方法,所以这个解决方案是直接的。
struct ColorA
{
float r, g, b, a;
auto to_tuple() const
{
return std::make_tuple(r, g, b, a);
}
};
int main()
{
float r, g, b, a;
ColorA color;
std::tie(r, g, b, a) = color.to_tuple();
return 0;
}
相关文章:
- C++将向量的向量拆分为向量的N个子向量
- 如何拆分文件中.txt字母并使用c ++使用数组进行扑克?
- OpenCV 4.1.2 - 从网络摄像头获取帧并将其拆分
- 使用 C++ 将命令行参数拆分为参数/向量
- C++(.cpp文件和.h文件)拆分代码并添加一个函数,提取 - 这很容易吗?
- 如何在C++中将数字拆分为数字
- 在线程之间拆分任务总是值得的吗?
- 将字符串拆分为标记,并将标记拆分为两个单独的数组
- 在 c++ 中拆分类和标头中的继承,错误
- 在矢量内拆分 deques
- 拆分重叠段
- 我还可以添加什么来按空格或空格正确拆分C++字符串?
- 通过空行提升拆分字符串
- 给定一个大小为 N 的数组 S,检查是否可以将序列拆分为两个序列
- 如何按多个括号类型拆分字符串,但仍将括号保留在C++?
- 将 Boost.Spirit.X3 解析器拆分为多个 TU
- 将字符串拆分为等长 c++ 的部分
- 将执行循环拆分为多个线程 (1-N-1-N-1..)
- 使用范围拆分string_view
- C++语法将ColorA拆分为浮点