Skip to content

Conversation

@mizdebsk
Copy link
Member

Replace calls to write() with operator<< when writing std::string to streams.

std::string::size() returns an unsigned value (size_t), while std::ostream::write() expects a signed std::streamsize, which introduces a narrowing conversion. Using operator<< is simpler, idiomatic, and avoids this type mismatch. It also improves readability without changing behavior.

Replace calls to write() with operator<< when writing std::string
to streams.

std::string::size() returns an unsigned value (size_t), while
std::ostream::write() expects a signed std::streamsize, which
introduces a narrowing conversion.  Using operator<< is simpler,
idiomatic, and avoids this type mismatch.  It also improves
readability without changing behavior.
@mkoncek
Copy link
Member

mkoncek commented Jul 23, 2025

I was completely aware of this. I decided to use .write because I believed operator<< does a lot of unnecessary checks, locale conversions and so. But after some investigation I believe it only happens with other overloaded variants of the operator and the overload for string / string_view is almost identical in implementation as pure write.

I would accept this but can you also check that what I said is true about similarity of the implementations?

@mizdebsk
Copy link
Member Author

what I said is true about similarity of the implementations

What do you mean? Can you elaborate?

@mkoncek
Copy link
Member

mkoncek commented Jul 23, 2025

I think my point was this: the intent is to write data to the stream unmodified.

I don't want formatting therefore i used .write, that is the reason.

@mizdebsk
Copy link
Member Author

Does it mean you won't accept the change? If so please close the PR.

@mkoncek mkoncek merged commit 56bd3fc into fedora-java:main Aug 21, 2025
1 check passed
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.

2 participants