Skip to content

Adds initial scaffolding for the split interface#2

Open
aryann wants to merge 3 commits intomainfrom
scaffolding
Open

Adds initial scaffolding for the split interface#2
aryann wants to merge 3 commits intomainfrom
scaffolding

Conversation

@aryann
Copy link
Copy Markdown
Collaborator

@aryann aryann commented May 10, 2026

The purpose of this PR is to start the discussion on the interface shape. Note the TODOs I've added in the code for some of the decisions we need to make.

We can either get this PR to a good shape and merge it, or merge it earlier and evolve it via future PRs.

aryann added 2 commits May 9, 2026 18:20
The purpose of this change is to start the conversation on the best interface for this library.
@aryann aryann requested a review from bartholomaios May 10, 2026 00:44
@coveralls
Copy link
Copy Markdown

coveralls commented May 10, 2026

Coverage Report for CI Build 25615829646

Warning

No base build found for commit 57bfa5e on main.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 100.0%

Details

  • Patch coverage: 6 of 6 lines across 1 file are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 6
Covered Lines: 6
Line Coverage: 100.0%
Coverage Strength: 7.17 hits per line

💛 - Coveralls

Copy link
Copy Markdown

@bartholomaios bartholomaios left a comment

Choose a reason for hiding this comment

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

We should have an overload that takes an output iterator (like std::format and std::format_to).

I think the simplest case should output to std::vector without needing the "say" vector.

Fundamentally, I see 3 parts to this library:

  • Delimiter/Pattern concept with implementations for all the common cases.
  • A range adapter for more general use-cases that has better ergonomics than the current std::ranges::views::split.
  • Algorithms that eagerly evaluate for simple use-cases. This should include splitting to tuple-like.


#include <string>
#include <string_view>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should these go here? Should they be guarded by BEMAN_STR_SPLIT_USE_MODULES()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It looks like we are the first ones to use the exemplar, and I am not 100% sure where these includes should go.

The namespace in todo.hpp is fully within the else branch of the BEMAN_STR_SPLIT_USE_MODULES, which is confusing to me (that would mean the TODO code will not be included when modules are enabled).

More broadly, we need to better understand the purpose of todo.hpp (we'll need to delete it eventually, but it's not clear to me why it was included in the first place).

// Ensures this constructor does not hijack copy and move construction which would fail to compile with a
// difficult-to-read wall of errors.
different_from<Range, split_by>)
constexpr explicit split_by(Range&& range) : delimiter_(std::ranges::begin(range), std::ranges::end(range)) {}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we could constrain this with: std::constructable_from<std::string, std::from_range_t, R>. We wouldn't need the std::string_view constructor in that case.

constexpr explicit split_by(std::string_view delimiter) : delimiter_(delimiter) {}

// Constructor for the single character case.
constexpr explicit split_by(char delimiter) : delimiter_(1, delimiter) {}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would prefer the single char case to be a separate delimiter (like abseil and std::string::find).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

split_by_char?

Also, see my comment about alternatives below and see if that's an approach you'd want to take instead.

@bartholomaios
Copy link
Copy Markdown

I'm going to take a first-pass at the range adapter today.

@aryann
Copy link
Copy Markdown
Collaborator Author

aryann commented May 10, 2026

I replied to some of your comments, but not all. I won't have time to work on this today. Do you want to merge this PR and make your changes on top? I agree with all your comments, so no objections on making the changes.

Please also see my TODO on modeling this as a series of function overloads. That's another direction that may produce better ergonomics and names.

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.

3 participants