diff options
author | Patrick Simianer <p@simianer.de> | 2014-08-23 22:59:16 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-08-23 22:59:16 +0100 |
commit | cef65063cec641a93973b38a48e100fdd115db44 (patch) | |
tree | 32d5f10757e021a9fad01156fbff62a96212f006 /fast/sparse_vector.hh | |
parent | 190f68c880eb27506669e95e2bc0493e2ec42c4c (diff) |
rewritten grammar
Diffstat (limited to 'fast/sparse_vector.hh')
-rw-r--r-- | fast/sparse_vector.hh | 21 |
1 files changed, 12 insertions, 9 deletions
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 |