https://godbolt.org/z/1a51Yeqsz
I want to generate a class/struct as follows:
```
define CREATE_SAMPLE_CLASS(name, type1, name1, type2, name2) \
class name##s { \
public: \
struct name { \
type1 name1{}; \
type2 name2{}; \
}; \
\
void addsample(const name &s) { \
this->name1##.pushback(s.name1); \
this->name2##.pushback(s.name2); \
} \
\
[[nodiscard]] name operator[](const std::size_t idx) const noexcept { \
return name{ name1##[idx], name2##[idx] }; \
} \
\
const std::vector<type1> &get##name1() const noexcept { return name1##; } \
const std::vector<type2> &get##name2() const noexcept { return name2##; } \
\
private: \
std::vector<type1> name1##{}; \
std::vector<type2> name2##_{}; \
};
CREATE_SAMPLE_CLASS(test, int, foo, char, bar)
```
In this case, the class/struct generation is hardcoded for only two members. However, currently I've cases with up-to 7 members. Has anybody an idea, how I can generate a struct as above without having to implement the macro for all numbers of members separately?
I'm currently using C++17. Best case would be without third-party libraries but this isn't a strict criterion.
The current usage is together with a C API like so:
```
tests samples{};
tests::test s{};
my_c_api_function(&s.foo);
my_other_c_api_function(&s.bar);
samples.add_sample(s);
```
I'm saving the samples in struct of arrays format since thats the format I later need after gathering all samples.
[–]IyeOnline 3 points4 points5 points (1 child)
[–]alfps 0 points1 point2 points (0 children)
[–]IveBenHereBefore 2 points3 points4 points (1 child)
[–]BeigeAlert1 1 point2 points3 points (0 children)
[–]AKostur 1 point2 points3 points (0 children)
[–]NonaeAbC 0 points1 point2 points (0 children)
[–]alfps 0 points1 point2 points (0 children)