Ah, the problem of detecting the last (or the first) element and treating it specially:
bool first = true;
[:expand(nonstatic_data_members_of(^^T)):] >> [&]<auto nsdm>{
if (not first) {
*out++ = ',';
*out++ = ' ';
}
first = false;
out = std::format_to(out,
".{}={}",
identifier_of(nsdm), m.[:nsdm:]);
};
I really wish there were a for/for-each variant that straightforwardly supported interspersed actions, something like this: [:expand(nonstatic_data_members_of(^^T)):] >> std::make_tuple([&]<auto nsdm>{
out = std::format_to(out,
".{}={}",
identifier_of(nsdm), m.[:nsdm:]);
}, [&]{
*out++ = ',';
*out++ = ' ';
});
An actual for-loop could also get a simple extension (which is quite easy to compile efficiently) but I can't figure out an intuitive enough syntax: for (int i = 0; i < 101; i++) {
std::cout << i;
} then {
std::cout << ", ";
}
is a bit fishy because the "then" block (can't call it "else", obviously) technically happens before the main loop body (i.e. inside it, the values of i would be 1, 2, ..., 100) but writing it before the main body would be even more confusing. Any suggestions? I'd really like to figure this feature out because I personally find it more useful than the "else block, but for the loops" feature.