-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++] P1789R3: Library Support for Expansion Statements #167184
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
Open
Tsche
wants to merge
13
commits into
llvm:main
Choose a base branch
from
Tsche:feature/decomposable_intseq
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
032858a
[libc++] P1789R3: Library Support for Expansion Statements
Tsche 7402319
fix formatting issues
Tsche 350a3a1
regenerate <version>
Tsche fd296c5
fix failing test
Tsche e309910
apply review comments
Tsche a795b2c
remove extraneous space
Tsche 2a238dc
address more review comments
Tsche 49c6594
add github issue to documentation, sort includes, minor style changes
Tsche 04a6f5f
rename tests
Tsche b9781f4
rename tests, add noexceptness and return type checks, add structured…
Tsche 94909a3
fix formatting issues
Tsche a7ed542
drop constexpr
Tsche 3e3ab8d
guard p1061 structured bindings behind FTM, add structured binding te…
Tsche 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,8 @@ | |||||
|
|
||||||
| #include <__config> | ||||||
| #include <__cstddef/size_t.h> | ||||||
| #include <__tuple/tuple_element.h> | ||||||
| #include <__tuple/tuple_size.h> | ||||||
| #include <__type_traits/is_integral.h> | ||||||
|
|
||||||
| #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||||||
|
|
@@ -67,6 +69,30 @@ _LIBCPP_HIDE_FROM_ABI constexpr void __for_each_index_sequence(index_sequence<_I | |||||
| } | ||||||
| # endif // _LIBCPP_STD_VER >= 20 | ||||||
|
|
||||||
| # if _LIBCPP_STD_VER >= 26 | ||||||
| // structured binding support for integer_sequence | ||||||
| template <class _Tp, _Tp... _Indices> | ||||||
| struct tuple_size<integer_sequence<_Tp, _Indices...>> : integral_constant<size_t, sizeof...(_Indices)> {}; | ||||||
|
|
||||||
| template <size_t _Ip, class _Tp, _Tp... _Indices> | ||||||
| struct tuple_element<_Ip, integer_sequence<_Tp, _Indices...>> { | ||||||
| static_assert(_Ip < sizeof...(_Indices), "Index out of bounds in std::tuple_element<> (std::integer_sequence)"); | ||||||
| using type _LIBCPP_NODEBUG = _Tp; | ||||||
| }; | ||||||
|
|
||||||
| template <size_t _Ip, class _Tp, _Tp... _Indices> | ||||||
| struct tuple_element<_Ip, const integer_sequence<_Tp, _Indices...>> { | ||||||
| static_assert(_Ip < sizeof...(_Indices), "Index out of bounds in std::tuple_element<> (const std::integer_sequence)"); | ||||||
| using type _LIBCPP_NODEBUG = _Tp; | ||||||
| }; | ||||||
|
|
||||||
| template <size_t _Ip, class _Tp, _Tp... _Indices> | ||||||
| _LIBCPP_HIDE_FROM_ABI constexpr _Tp get(integer_sequence<_Tp, _Indices...>) noexcept { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think we can mark |
||||||
| static_assert(_Ip < sizeof...(_Indices), "Index out of bounds in std::get<> (std::integer_sequence)"); | ||||||
| return _Indices...[_Ip]; | ||||||
| } | ||||||
| # endif // _LIBCPP_STD_VER >= 26 | ||||||
|
|
||||||
| # endif // _LIBCPP_STD_VER >= 14 | ||||||
|
|
||||||
| _LIBCPP_END_NAMESPACE_STD | ||||||
|
|
||||||
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
54 changes: 54 additions & 0 deletions
54
libcxx/test/std/utilities/intseq/intseq.binding/binding.compile.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,54 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
|
|
||
| // <utility> | ||
|
|
||
| // template<class T, T... Values> | ||
| // struct tuple_size<integer_sequence<T, Values...>>; | ||
| // template<size_t I, class T, T... Values> | ||
| // struct tuple_element<I, integer_sequence<T, Values...>>; | ||
| // template<size_t I, class T, T... Values> | ||
| // struct tuple_element<I, const integer_sequence<T, Values...>>; | ||
| // template<size_t I, class T, T... Values> | ||
| // constexpr T get(integer_sequence<T, Values...>) noexcept; | ||
|
|
||
| #include <cassert> | ||
| #include <tuple> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| constexpr void test() { | ||
| // std::tuple_size_v | ||
| using empty = std::integer_sequence<int>; | ||
| static_assert(std::tuple_size_v<empty> == 0); | ||
| static_assert(std::tuple_size_v<const empty> == 0); | ||
|
|
||
| using size4 = std::integer_sequence<int, 9, 8, 7, 2>; | ||
| static_assert(std::tuple_size_v<size4> == 4); | ||
| static_assert(std::tuple_size_v<const size4> == 4); | ||
|
|
||
| // std::tuple_element_t | ||
| static_assert(std::is_same_v<std::tuple_element_t<0, size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<1, size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<2, size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<3, size4>, int>); | ||
|
|
||
| static_assert(std::is_same_v<std::tuple_element_t<0, const size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<1, const size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<2, const size4>, int>); | ||
| static_assert(std::is_same_v<std::tuple_element_t<3, const size4>, int>); | ||
|
|
||
| // std::get | ||
| constexpr static size4 seq4{}; | ||
| static_assert(get<0>(seq4) == 9); | ||
| static_assert(get<1>(seq4) == 8); | ||
| static_assert(get<2>(seq4) == 7); | ||
| static_assert(get<3>(seq4) == 2); | ||
| } |
34 changes: 34 additions & 0 deletions
34
libcxx/test/std/utilities/intseq/intseq.binding/binding.verify.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,34 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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 | ||
|
|
||
| // <utility> | ||
|
|
||
| // template<size_t I, class T, T... Values> | ||
| // struct tuple_element<I, integer_sequence<T, Values...>>; | ||
| // template<size_t I, class T, T... Values> | ||
| // struct tuple_element<I, const integer_sequence<T, Values...>>; | ||
| // template<size_t I, class T, T... Values> | ||
| // constexpr T get(integer_sequence<T, Values...>) noexcept; | ||
|
|
||
| // Expect failures for tuple_element and get with empty integer_sequence | ||
|
|
||
| #include <utility> | ||
|
|
||
| void f() { | ||
| // expected-error-re@*:* {{static assertion failed{{.*}}Index out of bounds in std::tuple_element<> (std::integer_sequence)}} | ||
| using test1 = std::tuple_element_t<0, std::integer_sequence<int>>; | ||
| // expected-error-re@*:* {{static assertion failed{{.*}}Index out of bounds in std::tuple_element<> (const std::integer_sequence)}} | ||
| using test2 = std::tuple_element_t<0, const std::integer_sequence<int>>; | ||
|
|
||
| auto empty = std::integer_sequence<int>(); | ||
| // expected-error-re@*:* {{static assertion failed{{.*}}Index out of bounds in std::get<> (std::integer_sequence)}} | ||
| // expected-error-re@*:* {{invalid index 0 for pack {{.*}} of size 0}} | ||
| (void)std::get<0>(empty); | ||
| } |
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.
Nit: