Make contiguous 1d arrays/views model std::ranges::contiguous_range#137
Open
Wentzell wants to merge 1 commit into
Open
Make contiguous 1d arrays/views model std::ranges::contiguous_range#137Wentzell wants to merge 1 commit into
Wentzell wants to merge 1 commit into
Conversation
Turn the rank-1 nda::array_iterator into a std::contiguous_iterator when it traverses a contiguous, unit-stride chunk of memory, so that contiguous 1d arrays/views (array<T,1>, vector<T>, array_contiguous_view<T,1>) satisfy std::ranges::contiguous_range and interoperate with the std::ranges algorithms. iterators.hpp: - Add a `bool Contiguous` template parameter to array_iterator (defaulted to false). The rank-1 specialization exposes iterator_concept = contiguous_iterator_tag when Contiguous, else random_access_iterator_tag. - value_type is now cv-unqualified (std::remove_cv_t<T>), operator-> returns a real pointer (T*), and operator[] is const. The latter two also make the strided rank-1 iterator a genuine std::random_access_iterator. _impl_basic_array_view_common.hpp: - Drive the flag with _is_contiguous_1d = (Rank == 1) and has_contiguous(...). The Rank == 1 restriction is essential: a multi-dimensional contiguous array collapses to a rank-1 iterator internally, but must not advertise as a 1d contiguous range or nda::get_rank (which tests contiguous_range first) would report 1 for it. Since 1d arrays now model contiguous_range, guard the foreign-range overloads with `not MemoryArray<R>` to avoid ambiguity / wrong-branch selection: - operator==(array, range) / operator==(range, array) in basic_functions.hpp - the contiguous_range CTAD deduction guide in basic_array_view.hpp - the diag() contiguous_range branch in matrix_functions.hpp Add test/c++/nda_ranges.cpp covering the new concept guarantees, the deliberate exclusion of general/strided views and multi-dimensional arrays, and that array equality and std::ranges algorithms still work. Assisted-by: Claude <noreply@anthropic.com>
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.
This is a first draft to make 1-D contiguous nda types compliant with
std::ranges::contiguous_range