@@ -24,7 +24,7 @@ namespace cpptrace {
24
24
bool columns = true ;
25
25
bool show_filtered_frames = true ;
26
26
std::function<bool (const stacktrace_frame&)> filter;
27
- std::function<stacktrace_frame(stacktrace_frame&& )> transform;
27
+ std::function<stacktrace_frame(stacktrace_frame)> transform;
28
28
} options;
29
29
30
30
public:
@@ -55,15 +55,20 @@ namespace cpptrace {
55
55
void filter (std::function<bool (const stacktrace_frame&)> filter) {
56
56
options.filter = filter;
57
57
}
58
- void transform (std::function<stacktrace_frame(stacktrace_frame&& )> transform) {
58
+ void transform (std::function<stacktrace_frame(stacktrace_frame)> transform) {
59
59
options.transform = std::move (transform);
60
60
}
61
61
62
- std::string format (stacktrace_frame frame, detail::optional<bool > color_override = detail::nullopt) const {
62
+ std::string format (
63
+ const stacktrace_frame& input_frame,
64
+ detail::optional<bool > color_override = detail::nullopt
65
+ ) const {
63
66
std::ostringstream oss;
67
+ detail::optional<stacktrace_frame> transformed_frame;
64
68
if (options.transform ) {
65
- frame = options.transform (std::move (frame) );
69
+ transformed_frame = options.transform (input_frame );
66
70
}
71
+ const stacktrace_frame& frame = options.transform ? transformed_frame.unwrap () : input_frame;
67
72
print_frame_inner (oss, frame, color_override.value_or (options.color == color_mode::always));
68
73
return std::move (oss).str ();
69
74
}
@@ -156,10 +161,11 @@ namespace cpptrace {
156
161
}
157
162
const auto frame_number_width = detail::n_digits (static_cast <int >(frames.size ()) - 1 );
158
163
for (size_t i = 0 ; i < frames.size (); ++i) {
159
- auto frame = frames[i] ;
164
+ detail::optional<stacktrace_frame> transformed_frame ;
160
165
if (options.transform ) {
161
- frame = options.transform (std::move (frame) );
166
+ transformed_frame = options.transform (frames[i] );
162
167
}
168
+ const stacktrace_frame& frame = options.transform ? transformed_frame.unwrap () : frames[i];
163
169
if (options.filter && !options.filter (frame)) {
164
170
if (!options.show_filtered_frames ) {
165
171
counter++;
@@ -304,7 +310,7 @@ namespace cpptrace {
304
310
pimpl->filter (std::move (filter));
305
311
return *this ;
306
312
}
307
- formatter& formatter::transform (std::function<stacktrace_frame(stacktrace_frame&& )> transform) {
313
+ formatter& formatter::transform (std::function<stacktrace_frame(stacktrace_frame)> transform) {
308
314
pimpl->transform (std::move (transform));
309
315
return *this ;
310
316
}
0 commit comments