Skip to content

Commit 076c408

Browse files
committed
fix: Remove stream reference from stats_line
We never use anything other than `std::cout` and the class should be refactored anyway.
1 parent c03f296 commit 076c408

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

include/pisa/util/util.hpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,23 @@ function_iterator<State, AdvanceFunctor, ValueFunctor> make_function_iterator(
113113
}
114114

115115
struct stats_line {
116-
stats_line() : m_out(std::cout) { m_out << "{"; }
117-
explicit stats_line(std::ostream& out) : m_out(out) { m_out << "{"; }
116+
stats_line() { std::cout << "{"; }
118117
stats_line(stats_line const&) = default;
119118
stats_line(stats_line&&) noexcept = default;
120119
stats_line& operator=(stats_line const&) = default;
121120
stats_line& operator=(stats_line&&) noexcept = default;
122-
~stats_line() { m_out << "}" << std::endl; }
121+
~stats_line() { std::cout << "}" << std::endl; }
123122

124123
template <typename K, typename T>
125124
stats_line& operator()(K const& key, T const& value) {
126125
if (!first) {
127-
m_out << ", ";
126+
std::cout << ", ";
128127
} else {
129128
first = false;
130129
}
131130

132131
emit(key);
133-
m_out << ": ";
132+
std::cout << ": ";
134133
emit(value);
135134
return *this;
136135
}
@@ -143,27 +142,27 @@ struct stats_line {
143142
private:
144143
template <typename T>
145144
void emit(T const& v) const {
146-
m_out << v;
145+
std::cout << v;
147146
}
148147

149148
// XXX properly escape strings
150-
void emit(const char* s) const { m_out << '"' << s << '"'; }
149+
void emit(const char* s) const { std::cout << '"' << s << '"'; }
151150

152151
void emit(std::string const& s) const { emit(s.c_str()); }
153152

154153
template <typename T>
155154
void emit(std::vector<T> const& v) const {
156-
m_out << "[";
155+
std::cout << "[";
157156
bool first = true;
158157
for (auto const& i: v) {
159158
if (first) {
160159
first = false;
161160
} else {
162-
m_out << ", ";
161+
std::cout << ", ";
163162
}
164163
emit(i);
165164
}
166-
m_out << "]";
165+
std::cout << "]";
167166
}
168167

169168
template <typename K, typename V>
@@ -175,7 +174,7 @@ struct stats_line {
175174
template <typename Tuple, size_t Pos>
176175
typename std::enable_if<Pos != 0, void>::type emit_tuple_helper(Tuple const& t) const {
177176
emit_tuple_helper<Tuple, Pos - 1>(t);
178-
m_out << ", ";
177+
std::cout << ", ";
179178
emit(std::get<Pos>(t));
180179
}
181180

@@ -186,17 +185,16 @@ struct stats_line {
186185

187186
template <typename... Tp>
188187
void emit(std::tuple<Tp...> const& t) const {
189-
m_out << "[";
188+
std::cout << "[";
190189
emit_tuple_helper<std::tuple<Tp...>, sizeof...(Tp) - 1>(t);
191-
m_out << "]";
190+
std::cout << "]";
192191
}
193192

194193
template <typename T1, typename T2>
195194
void emit(std::pair<T1, T2> const& p) const {
196195
emit(std::make_tuple(p.first, p.second));
197196
}
198197

199-
std::ostream& m_out;
200198
bool first{true};
201199
};
202200

0 commit comments

Comments
 (0)