[core] Support string views and C strings in Join - #23392
Open
Shubham-Padkonde wants to merge 2 commits into
Open
Shubham-Padkonde wants to merge 2 commits into
Shubham-Padkonde wants to merge 2 commits into
Conversation
pcanal
reviewed
Sep 16, 2026
| return ""; | ||
|
|
||
| return std::accumulate(std::next(begin), end, *begin, [&sep](auto const &a, auto const &b) { return a + sep + b; }); | ||
| std::string result(*begin++); |
Member
There was a problem hiding this comment.
Isn't there a working version using std::accumulate rather than an explicit for loop?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ROOT::Joincannot compile when its input is a container ofstd::string_viewor an array of C strings.std::accumulateinfers the accumulator type from the input element, and the concatenation assumes owning strings.Build the result in an owning
std::stringand 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.