From cef65063cec641a93973b38a48e100fdd115db44 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sat, 23 Aug 2014 22:59:16 +0100 Subject: rewritten grammar --- fast/sparse_vector.hh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'fast/sparse_vector.hh') diff --git a/fast/sparse_vector.hh b/fast/sparse_vector.hh index 3583240..9d815ff 100644 --- a/fast/sparse_vector.hh +++ b/fast/sparse_vector.hh @@ -20,6 +20,7 @@ struct SparseVector { V zero = 0.f; SparseVector() {}; + SparseVector(string& s) { from_s(this, s); @@ -147,10 +148,9 @@ struct SparseVector { } } - string - repr() const + ostream& + repr(ostream& os) const { - ostringstream os; os << "SparseVector<{"; for (auto it = m_.cbegin(); it != m_.cend(); it++) { os << "'" << it->first << "'=" << it->second; @@ -159,12 +159,11 @@ struct SparseVector { } os << "}>"; - return os.str(); + return os; }; - string - escaped(bool quote_keys=false) const { - ostringstream os; + ostream& + escaped(ostream& os, bool quote_keys=false) const { for (auto it = m_.cbegin(); it != m_.cend(); it++) { if (quote_keys) os << '"'; os << util::json_escape(it->first); @@ -173,10 +172,14 @@ struct SparseVector { if (next(it) != m_.cend()) os << " "; } - return os.str(); + return os; }; - friend ostream& operator<<(ostream& os, const SparseVector& v) { return os << v.repr(); } + friend ostream& + operator<<(ostream& os, const SparseVector& v) + { + return v.repr(os); + } }; } // namespace -- cgit v1.2.3