Sadly there is no reflection in C++, so there isn't a good way to do what you want.
With modern C++ you could do something like this:
#include <cstddef>
#include <iostream>
#include <tuple>
#include <utility>
struct Line
{
int date;
int time;
float open;
float high;
float low;
float close;
float sd;
float long_mo;
float short_mo;
};
template <typename ...P, std::size_t ...I, typename F>
void for_each_tuple_elem_low(std::tuple<P...> t, std::index_sequence<I...>, F &&func)
{
(void(func(std::get<I>(t))) , ...);
}
template <typename ...P, typename F> void for_each_tuple_elem(std::tuple<P...> t, F &&func)
{
for_each_tuple_elem_low(t, std::make_index_sequence<sizeof...(P)>{}, func);
}
int main()
{
Line obj;
auto &[x1,x2,x3,x4,x5,x6,x7,x8,x9] = obj;
auto tuple = std::tie(x1,x2,x3,x4,x5,x6,x7,x8,x9);
int i = 0;
for_each_tuple_elem(tuple, [&](auto &ref)
{
ref = i++;
});
}
Here, the boilerplate is reduced to typing out the names of the structured bindings twice: x1,x2,x3,x4,x5,x6,x7,x8,x9
.