kraken: csv: fix comma separation logic

Unfortunately, `std::ostream_iterator` puts its separator *after* every
element, not *in-between* each element.
This commit is contained in:
Bruno BELANYI 2022-03-12 00:45:27 +01:00
parent 6ee4e5b554
commit bd072e1025
2 changed files with 8 additions and 4 deletions

View file

@ -8,8 +8,12 @@ namespace kraken::csv {
void write_csv(std::ostream& output, csv_type const& csv) {
for (const auto& line : csv) {
std::ranges::copy(line,
std::ostream_iterator<std::string>{output, ","});
bool first = true;
for (const auto& atom : line) {
output << (first ? "" : ",") << atom;
first = false;
};
output << '\n';
}
}