Tuple protocol for fixed-size span (P3786R2)#7
Open
SamareshSingh wants to merge 4 commits intomainfrom
Open
Conversation
Adds the three pieces from P3786R2: - std::tuple_size<span<T, N>> - integral_constant<size_t, N> - std::tuple_element<I, span<T, N>> - using type = T& - get<I>(span<T, N>) returning T&, in beman::span so ADL finds it for structured bindings All three are gated on N != dynamic_extent via constrained partial specialization, so std::tuple_size<span<T>> falls back to the undefined primary template and remains SFINAE-friendly for the tuple-like concept. Top-level cv on the span is handled automatically by the existing std::tuple_size<const T> / std::tuple_element<I, const T> partial specs. Six new tests cover tuple_size value, tuple_element returning references (including const-element-type and top-level-const cases), get returning a reference to the underlying element, structured bindings binding by reference, and the dynamic_extent SFINAE behaviour. Fixes #4
# Conflicts: # include/beman/span/span.hpp
Pure formatter output. Reflows the new tuple_size / tuple_element / get specializations and tightens up the SpanTuple tests under the .clang-format AlignConsecutiveDeclarations and ColumnLimit rules. Also picks up the at() test alignment carried in via the merge.
# Conflicts: # tests/beman/span/span.test.cpp
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.
Implements P3786R2 so fixed-size spans support the tuple protocol and structured bindings.
Three additions, per the paper:
std::tuple_size<span<T, N>>specialised tointegral_constant<size_t, N>.std::tuple_element<I, span<T, N>>withusing type = T&(a reference, since a span element lives outside the span).get<I>(span<T, N>)returningT&. Lives inbeman::spanso ADL picks it up forauto& [a, b, c] = s;.All three are gated on
N != dynamic_extentvia constrained partial specialisation. Forspan<T>(dynamic) the specialisations don't apply, sostd::tuple_size<span<T>>falls back to the undefined primary template — that's the SFINAE-friendly behaviour thetuple-likeconcept relies on.Top-level cv on the span itself (
const span<T, N>) is handled by the existingstd::tuple_size<const T>/std::tuple_element<I, const T>partial specialisations in the standard, so we don't need to do anything for that case.Six new tests:
tuple_size_vfor fixed extents including 0tuple_element_treturningT&/const T&/int&forconst span<int, N>get<I>returning a reference, with mutation visible through the underlying arrayLocal: 51/51 passing.
Fixes #4