Skip to content

Fix field width handling in bitset stream output - #479

Merged
Neargye merged 2 commits into
Neargye:masterfrom
fhgffy:fix/ostream-field-width
Oct 4, 2026
Merged

Neargye merged 2 commits into
Neargye:masterfrom
fhgffy:fix/ostream-field-width

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

containers::bitset::operator<< uses unformatted write(), so it leaves the stream's field width for the next insertion. For example, std::setfill('_') << std::setw(6) << bitset{Color::RED} << '!' produces RED_____! instead of ___RED!.

Insert a basic_string_view matching the stream's character traits as one formatted field. This respects alignment and fill, consumes the field width, and preserves the complete name's length. Regression tests cover left/right alignment, a width smaller than the name, empty bitsets, custom traits, and wide-character aliases.

Validation on Windows with MinGW GCC 15.1.0 and CMake 4.3.2:

  • The minimal reproducer and the new project regression fail on the unchanged base ccb76393; the reproducer passes after the fix.
  • Release CMake build with the project's strict warnings; CTest passes all 28 available cases across C++17, C++20, C++23, and C++26 compiler-specific reflection.
  • All 9 public headers pass CMake's independent interface-header verification target.
  • git diff --check passes.

C++26 standard reflection and C++ modules were not exercised locally.

@fhgffy
fhgffy marked this pull request as ready for review October 3, 2026 23:59
@Neargye

Neargye commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

@fhgffy
Thanks for the fix! Could you please remove the added comments? The code and test names are clear without them.

@fhgffy

fhgffy commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Removed the comments added by this PR, including the date annotations. The fix and regression tests are unchanged. Rebuilt and ran test_containers-cpp17 and test_wchar_t-cpp17; both pass.

@Neargye

Neargye commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR!

@Neargye
Neargye merged commit e71d33d into Neargye:master Oct 4, 2026
41 checks 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