Skip to content

Conversation

@jwaldrop107
Copy link
Member

@jwaldrop107 jwaldrop107 commented Mar 7, 2025

Description
As is, stream output for classes derived from PolymorphicBase first converts to a string then adds the string to the stream output. This behavior prevents controlling the print precision of floating point values as they never see options like std::fixed or std::setprecision. This PR adds the add_to_stream method as an intermediate step that derived classes can use to more directly interact with the output stream, but defaults to the existing behavior for anything that doesn't implement add_to_stream_.

@jwaldrop107 jwaldrop107 requested a review from ryanmrichard March 7, 2025 17:13
@jwaldrop107 jwaldrop107 self-assigned this Mar 7, 2025
Copy link
Member

@ryanmrichard ryanmrichard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a much better solution than to_string. I was running into a different problem where I wanted to change what's being printed based on the log level. I think that could be accomplished by overloading add_to_stream (you don't have to do it now, I'm just pointing it out in case it comes up later).

@jwaldrop107 jwaldrop107 merged commit 46673af into master Mar 7, 2025
9 checks passed
@jwaldrop107 jwaldrop107 deleted the print_precision branch March 7, 2025 17:34
@jwaldrop107
Copy link
Member Author

🚀 [bumpr] Bumped! New version:v0.0.49 Changes:v0.0.48...v0.0.49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants