Skip to content

Don't print extra spaces in println for empty containers - #232

Open
ItsDeadlyProgrammer wants to merge 1 commit into
MikeMirzayanov:masterfrom
ItsDeadlyProgrammer:println-empty-container
Open

ItsDeadlyProgrammer wants to merge 1 commit into
MikeMirzayanov:masterfrom
ItsDeadlyProgrammer:println-empty-container

Conversation

@ItsDeadlyProgrammer

@ItsDeadlyProgrammer ItsDeadlyProgrammer commented Oct 9, 2026 •

Copy link
Copy Markdown

Fixes #101.

println always puts a space between its arguments, so an empty container leaves extra spaces behind: with an empty a, println(a.size(), a) prints "0 " and println(5, a, 7) prints "5 7". Printing n and then the array is very common in generators, so for n = 0 the test file ends up with a trailing space, which a validator doing readInt() + readEoln() rejects.

Now the space is only printed before an argument that actually prints something, so empty containers are just skipped. Strings are printed as before (println(string(), 5) still gives " 5").

Added tests/test-012_println-empty. The ref comparison ignores whitespace, so the test captures cout and checks the exact output with ensure. It fails without the change and passes with it. Built with g++ for C++11, 14 and 17, and all generators, checkers, validators and interactors in the repo still compile.

@ItsDeadlyProgrammer

Copy link
Copy Markdown
Author

Rebased onto master. The variadic println now goes through the same skip-empty helper, and the test moved to test-012_println-empty because 009 is taken. test-008_format, test-011_shadow and the new test pass with g++ for C++11, 14 and 17.

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.

println(a.size(), a) prints extra space when a is empty

1 participant