-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++][ranges] P3060R3: Add std::views::indices(n)
#146823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Zingam
merged 28 commits into
llvm:main
from
H-G-Hristov:hgh/libcxx/P3060R3-Add-std_views_indices
Oct 6, 2025
Merged
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f81e4a3
[libc++][ranges] P3060R3: Add `std::views::indices(n)`
H-G-Hristov 3e9593d
Implement and cleanup
H-G-Hristov 1572f7a
Update version
H-G-Hristov a27ae43
Add release notes
H-G-Hristov a647295
Cleanup
H-G-Hristov 9f06e29
House keeping
H-G-Hristov 35c8579
Addressed review comments
H-G-Hristov b0c1a84
Update libcxx/modules/std/ranges.inc
Zingam 4fbdb9f
Made the lambda `static`
H-G-Hristov 3c56946
Updated status
H-G-Hristov af7fe91
Update test
H-G-Hristov cd478e8
LLVM22
H-G-Hristov f0bad15
Update libcxx/docs/ReleaseNotes/22.rst
H-G-Hristov ec1fc1a
Update CPO test
H-G-Hristov 09d1f47
Merge branch 'main' into hgh/libcxx/P3060R3-Add-std_views_indices
H-G-Hristov 174c4c1
Merge branch 'main' into hgh/libcxx/P3060R3-Add-std_views_indices
Zingam 5931d85
Merge branch 'main' into hgh/libcxx/P3060R3-Add-std_views_indices
H-G-Hristov 87c7885
Merge branch 'main' into hgh/libcxx/P3060R3-Add-std_views_indices
H-G-Hristov 9610de0
Merge branch 'main' into hgh/libcxx/P3060R3-Add-std_views_indices
Zingam 34f7565
Merge branch 'main' into hgh/libcxx/P3060R3-Add-std_views_indices
Zingam 38efb3c
Merge branch 'main' into hgh/libcxx/P3060R3-Add-std_views_indices
Zingam 915f38f
Merge branch 'main' into hgh/libcxx/P3060R3-Add-std_views_indices
Zingam b995e9a
Merge branch 'main' into hgh/libcxx/P3060R3-Add-std_views_indices
H-G-Hristov b587330
Merge branch 'main' into hgh/libcxx/P3060R3-Add-std_views_indices
H-G-Hristov cbc4ff6
Updated test
H-G-Hristov df9ac54
Update libcxx/test/std/ranges/range.factories/range.iota.view/indices…
Zingam 394a10c
Update libcxx/test/std/ranges/range.factories/range.iota.view/indices…
Zingam e55641b
Merge branch 'main' into hgh/libcxx/P3060R3-Add-std_views_indices
H-G-Hristov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
99 changes: 99 additions & 0 deletions
99
libcxx/test/std/ranges/range.factories/range.iota.view/indices.pass.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// REQUIRES: std-at-least-c++26 | ||
|
||
// ranges | ||
|
||
// inline constexpr unspecified indices = unspecified; | ||
|
||
#include <cassert> | ||
#include <cstddef> | ||
#include <ranges> | ||
#include <vector> | ||
|
||
#include "test_macros.h" | ||
#define TEST_HAS_NO_INT128 // Size cannot be larger than 64 bits | ||
#include "type_algorithms.h" | ||
|
||
#include "types.h" | ||
|
||
// Test SFINAE. | ||
|
||
template <typename SizeType> | ||
concept HasIndices = requires(SizeType s) { std::ranges::views::indices(s); }; | ||
|
||
struct NotIntegerLike {}; | ||
|
||
void test_SFINAE() { | ||
static_assert(HasIndices<std::size_t>); | ||
types::for_each(types::integer_types(), []<typename T> { static_assert(HasIndices<T>); }); | ||
|
||
// Non-integer-like types should not satisfy HasIndices | ||
static_assert(!HasIndices<bool>); | ||
static_assert(!HasIndices<float>); | ||
static_assert(!HasIndices<void>); | ||
static_assert(!HasIndices<SomeInt>); // Does satisfy is_integer_like, but not the conversion to std::size_t | ||
static_assert(!HasIndices<NotIntegerLike>); | ||
} | ||
|
||
constexpr bool test() { | ||
{ | ||
auto indices_view = std::ranges::views::indices(5); | ||
static_assert(std::ranges::range<decltype(indices_view)>); | ||
|
||
assert(indices_view.size() == 5); | ||
|
||
assert(indices_view[0] == 0); | ||
assert(indices_view[1] == 1); | ||
assert(indices_view[2] == 2); | ||
assert(indices_view[3] == 3); | ||
assert(indices_view[4] == 4); | ||
} | ||
|
||
{ | ||
std::vector v(5, 0); | ||
|
||
auto indices_view = std::ranges::views::indices(std::ranges::size(v)); | ||
static_assert(std::ranges::range<decltype(indices_view)>); | ||
|
||
assert(indices_view.size() == 5); | ||
|
||
assert(indices_view[0] == 0); | ||
assert(indices_view[1] == 1); | ||
assert(indices_view[2] == 2); | ||
assert(indices_view[3] == 3); | ||
assert(indices_view[4] == 4); | ||
} | ||
|
||
{ | ||
std::vector v(5, SomeInt{}); | ||
|
||
auto indices_view = std::ranges::views::indices(std::ranges::size(v)); | ||
static_assert(std::ranges::range<decltype(indices_view)>); | ||
|
||
assert(indices_view.size() == 5); | ||
|
||
assert(indices_view[0] == 0); | ||
assert(indices_view[1] == 1); | ||
assert(indices_view[2] == 2); | ||
assert(indices_view[3] == 3); | ||
assert(indices_view[4] == 4); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
int main(int, char**) { | ||
test_SFINAE(); | ||
H-G-Hristov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Zingam marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
Zingam marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
test(); | ||
static_assert(test()); | ||
|
||
return 0; | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think libc++ provides any (cv-unqualified)
__integer_like
but notweakly_incrementable
type at this moment. So, no change requested at this moment. Although theoperator()
will need to be constrained harder once libc++ starts to provide such an integer-class type.