diff --git a/test/test_transaction_examples.cxx b/test/test_transaction_examples.cxx index ebbb045f..210177d8 100644 --- a/test/test_transaction_examples.cxx +++ b/test/test_transaction_examples.cxx @@ -377,6 +377,11 @@ class byte_appender using iterator_category = std::output_iterator_tag; using value_type = void; + explicit byte_appender(std::vector& output) + : buffer_{ output } + { + } + auto operator=(char ch) -> byte_appender& { buffer_.push_back(static_cast(ch)); @@ -398,13 +403,8 @@ class byte_appender return *this; } - [[nodiscard]] auto buffer() const -> const std::vector& - { - return buffer_; - } - private: - std::vector buffer_{}; + std::vector& buffer_; }; template<> @@ -452,7 +452,14 @@ class ledger [[nodiscard]] auto to_csv() const -> std::vector { - byte_appender output; + if (entries_.empty()) { + return { + std::byte{ '\n' }, + }; + } + + std::vector buffer; + byte_appender output{ buffer }; fmt::format_to(output, "Date,Description,Account,Debit,Credit\n"); for (const auto& entry : entries_) { @@ -464,7 +471,7 @@ class ledger entry.debit, entry.credit); } - return output.buffer(); + return buffer; } static auto from_csv(const std::vector& blob) -> ledger