Skip to content

[core] Support string views and C strings in Join - #23392

Open
Shubham-Padkonde wants to merge 2 commits into
root-project:masterfrom
Shubham-Padkonde:fix/join-string-views
Open

Shubham-Padkonde wants to merge 2 commits into
root-project:masterfrom
Shubham-Padkonde:fix/join-string-views

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown

ROOT::Join cannot compile when its input is a container of std::string_view or an array of C strings. std::accumulate infers the accumulator type from the input element, and the concatenation assumes owning strings.

Build the result in an owning std::string and append each element and separator. This also avoids repeatedly copying the entire accumulated prefix. Existing empty-string and separator behavior is preserved.

Add coverage for non-null-terminated string views, the iterator overload, and a C-string array containing an empty element.

Validation: the new tests fail to compile on the original implementation. All six StringUtils tests pass with the fix, built directly with GCC 13, C++17, -Wall -Wextra -Werror, and GoogleTest. Changed lines were formatted with the repository clang-format configuration. Full ROOT build and CI were not run locally.

AI disclosure: Codex prepared the implementation, tests, and description. The contributor must review and understand the patch before submitting, as required by ROOT's contribution policy.

return "";

return std::accumulate(std::next(begin), end, *begin, [&sep](auto const &a, auto const &b) { return a + sep + b; });
std::string result(*begin++);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't there a working version using std::accumulate rather than an explicit for loop?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants