Merged
Conversation
Adds the two mutating shrink operations to dynamic-extent span: - remove_prefix(n): drops the first n elements - remove_suffix(n): drops the last n elements Both are gated to dynamic_extent only via the same SFINAE pattern the default constructor uses. Fixed-extent spans carry their size in the type, so an in-place size mutation isn't representable - matching string_view (no fixed extent) and Abseil's Span (dynamic only). Eight new tests cover n=0, partial shrink, full shrink to empty, both operations combined, and a detection-idiom check confirming fixed-extent spans do not expose these methods. Fixes #3
JeffGarland
reviewed
Apr 26, 2026
JeffGarland
requested changes
Apr 26, 2026
JeffGarland
approved these changes
Apr 26, 2026
Member
|
Also, I don't know how you want to handle this -- fine as another issue, but the readme/examples should be updated to highlight the new features |
Addresses Jeff's review feedback on PR #8: Beman targets C++20 as baseline, so the new modifiers should use a requires clause rather than the SFINAE-style enable_if_t shim. Behavior is identical (the existing void_t-based detection tests still pass), just clearer at the point of declaration. Also picks up the clang-format pass over the at() tests carried in via the merge of main.
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.
Adds the two in-place shrink operations from P3729 — same shape as
string_view's methods and Abseil'sSpan.Both are gated on
Extent == dynamic_extentvia the sameenable_if_ttrick the default constructor already uses. A fixed-extentspan<T, N>carries its size in the type, so an in-place size mutation isn't representable, there is no sensible thing to do for the fixed case, andstring_view(which has no fixed-extent equivalent) sets the precedent.Eight new tests:
n == 0no-op for bothdata()pointer move correctly for prefix; data unchanged for suffix)remove_prefix(size())/remove_suffix(size())both empty the span)bsp::span<int>exposes both methods andbsp::span<int, 3>does notLocal: 53/53 passing.
Fixes #3