Reputation: 259
I remember being able to do something like this but I cant remember how. I want to extract the floats from a ColorA data type, what is the shortest syntax to do this in C++?
ColorA(r,g,b,a) = material.getAmbient();
Upvotes: 0
Views: 47
Reputation:
You can use std::tie
here if you're willing to provide a to_tuple
function. A tuple conversion function has problems with a nastier workaround so this solution is straight forward.
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;
}
Upvotes: 1