The trailing newline is probably useful for manual parsing of the input, but it's not when solving challenges. Extra care must be taken to handle the empty line which is annoying. For example:
struct Foo {
Foo(const std::string& x) {
// Parse x but be prepared for x.empty()
}
};
void SolveChallenge() {
for(const auto& line : mInput) {
Foo f{line};
f.bar();
}
}
This is not a big deal when manually iterating the input, but if you use an STL algorithm:
std::vector<Foo> foos;
// An extra Foo is made because of trailing new line
std::transform(mInput.begin(), mInput.end(), std::back_inserter(foos),
[](const std::string& x) { return Foo{x}; }
);
The trailing newline is probably useful for manual parsing of the input, but it's not when solving challenges. Extra care must be taken to handle the empty line which is annoying. For example:
This is not a big deal when manually iterating the input, but if you use an STL algorithm: