Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split a struct into a tuple [duplicate]

The question is pretty straight, how could I generate :

std::tuple<float, int, double>

If I know the type :

struct Foo { float a; int b; double c; };

And how could I retrieve the data, in both convertion?

like image 220
Mathieu Van Nevel Avatar asked Feb 24 '18 15:02

Mathieu Van Nevel


1 Answers

You cannot do this in C++, as it would require a language feature known as reflection.

Instead, "manually" build the tuple or just begin with a tuple in the first place.

Alternatively, you could build a script in Python (or similar) to preprocess your code and auto-generate the resulting conversion.

like image 61
Lightness Races in Orbit Avatar answered Sep 30 '22 01:09

Lightness Races in Orbit