Call me a cheat, but...
struct Color final
{
double grey;
double rgb[3];
};
// the cheet
#define make_color( x, a, b ) Color x { a, b[0], b[1], b[2] }
int main()
{
double myRGB[3]{ 2, 6, 9 };
make_color( c, 10, myRGB ) ; // single line construction
printf("\nColor grey: %f\t rgb:[ %f, %f, %f ]", c.grey, c.rgb[0], c.rgb[1], c.rgb[2] ) ;
}
But, since that is pretty atrocious C++, I have taken a liberty of producing something slightly better...
struct Color final
{
double grey;
double rgb[3];
};
auto make_color ( double a, const double(&b)[3] ) { return Color { a, b[0], b[1], b[2] }; };
auto make_color ( double a, double b, double c, double d ) { return Color { a, b, c, d }; };
auto print_color ( Color c ) { printf("\nColor grey: %f\t rgb:[ %f, %f, %f ]", c.grey, c.rgb[0], c.rgb[1], c.rgb[2] ) ; }
//
int main()
{
double myRGB[3]{ 2, 6, 9 };
auto c = make_color( 10, myRGB ) ;
print_color(c);
auto z = make_color( 10, 0xFF, 0xA0, 0xB0 ) ;
print_color(z);
}
All in a good old SO tradition: do not question the question :)
(the mandatory Wandbox is here)
ps: I like your approach Oliver, although you do not need double braces in those init lists, of course.
Colorstructure.Color c = { 10, 2, 6, 9}