@@ -24,7 +24,7 @@ namespace cpptrace {
2424 bool columns = true ;
2525 bool show_filtered_frames = true ;
2626 std::function<bool (const stacktrace_frame&)> filter;
27- std::function<stacktrace_frame(stacktrace_frame&& )> transform;
27+ std::function<stacktrace_frame(stacktrace_frame)> transform;
2828 } options;
2929
3030 public:
@@ -55,15 +55,20 @@ namespace cpptrace {
5555 void filter (std::function<bool (const stacktrace_frame&)> filter) {
5656 options.filter = filter;
5757 }
58- void transform (std::function<stacktrace_frame(stacktrace_frame&& )> transform) {
58+ void transform (std::function<stacktrace_frame(stacktrace_frame)> transform) {
5959 options.transform = std::move (transform);
6060 }
6161
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 {
6366 std::ostringstream oss;
67+ detail::optional<stacktrace_frame> transformed_frame;
6468 if (options.transform ) {
65- frame = options.transform (std::move (frame) );
69+ transformed_frame = options.transform (input_frame );
6670 }
71+ const stacktrace_frame& frame = options.transform ? transformed_frame.unwrap () : input_frame;
6772 print_frame_inner (oss, frame, color_override.value_or (options.color == color_mode::always));
6873 return std::move (oss).str ();
6974 }
@@ -156,10 +161,11 @@ namespace cpptrace {
156161 }
157162 const auto frame_number_width = detail::n_digits (static_cast <int >(frames.size ()) - 1 );
158163 for (size_t i = 0 ; i < frames.size (); ++i) {
159- auto frame = frames[i] ;
164+ detail::optional<stacktrace_frame> transformed_frame ;
160165 if (options.transform ) {
161- frame = options.transform (std::move (frame) );
166+ transformed_frame = options.transform (frames[i] );
162167 }
168+ const stacktrace_frame& frame = options.transform ? transformed_frame.unwrap () : frames[i];
163169 if (options.filter && !options.filter (frame)) {
164170 if (!options.show_filtered_frames ) {
165171 counter++;
@@ -304,7 +310,7 @@ namespace cpptrace {
304310 pimpl->filter (std::move (filter));
305311 return *this ;
306312 }
307- formatter& formatter::transform (std::function<stacktrace_frame(stacktrace_frame&& )> transform) {
313+ formatter& formatter::transform (std::function<stacktrace_frame(stacktrace_frame)> transform) {
308314 pimpl->transform (std::move (transform));
309315 return *this ;
310316 }
0 commit comments