-
Notifications
You must be signed in to change notification settings - Fork 1.6k
P2165R4: Compatibility Between tuple, pair, And tuple-like Objects
#3372
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
Stephan T. Lavavej (StephanTLavavej)
merged 45 commits into
microsoft:main
from
JMazurkiewicz:tuple_like
Feb 26, 2023
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
61eff70
Add feature test macro
JMazurkiewicz dee5c28
Apply changes from `range.subrange`
JMazurkiewicz 079cc4f
Apply changes from `range.elements.view`
JMazurkiewicz 4394897
Apply changes from `associative.general`
JMazurkiewicz 2f17692
Implement `basic_common_reference` and `common_type` for `tuple-like`…
JMazurkiewicz 14b2efc
Implement `common_reference` and `common_type` tests
JMazurkiewicz 8ab8d84
Remove useless forward declarations of `get(tuple)` function
JMazurkiewicz f812a39
Test changes to `[associative.general]`
JMazurkiewicz e19cfea
New `tuple` members + tests
JMazurkiewicz cabb123
Implement comparison operators + tests
JMazurkiewicz c397fda
Make `common_reference` tests strict
JMazurkiewicz 78146ba
Test update
JMazurkiewicz d8e699f
Implement tuple special functions + tests
JMazurkiewicz cc13eed
Polishing up 💎
JMazurkiewicz eb44051
ADD WORKAROUND FOR LLVM-59827
JMazurkiewicz 60e8b16
Improve new assignment operators
JMazurkiewicz 848a00a
Skip some LLVM tests
JMazurkiewicz 2c4d425
`common_type<pair>` and `common_reference<pair>` should be available …
JMazurkiewicz 91322ab
Fix constructors (again), no fix for comparisons (yet)
JMazurkiewicz f5bac0e
Quick comment fix
JMazurkiewicz 14cad2d
YEAH, I THINK COMPARISON OPERATORS ARE FINE NOW
JMazurkiewicz 6a860d5
Remove redundant remove_cvref_t
JMazurkiewicz a168536
Comment DevCom-10265322 workaround
JMazurkiewicz 75a0964
Implement SFINAE-friendly <=> (thanks @frederick-vs-ja!)
JMazurkiewicz 325884d
Turn traits structures back into variables
JMazurkiewicz 1bc4ff3
Add extra tests for DevCom-10265237
JMazurkiewicz 7b92933
Try to fix `/permissive` tests
JMazurkiewicz 203be06
Replace fold expressions with `conjunction_v`
JMazurkiewicz 69accc6
Fix ICEs with this one simple trick!
JMazurkiewicz cf148b9
Address some comments from @StephanTLavavej
JMazurkiewicz bb1b1ab
More comments!
JMazurkiewicz ae8b0ce
Quick `static_assert` fix
JMazurkiewicz c5e3ce8
Merge branch 'main' into tuple_like
JMazurkiewicz 760b0c8
More `signed, unsigned` => `int, unsigned int`.
StephanTLavavej c0a3e01
Merge branch 'main' into tuple_like
JMazurkiewicz 1e5b263
Move libcxx skips
JMazurkiewicz baf59fe
Merge branch 'main' into tuple_like
CaseyCarter a237351
Remove `int main() {} // COMPILE-ONLY` from tests
JMazurkiewicz 64c2276
`static_cast<void>` -> `(void)`
JMazurkiewicz fd16c01
Trailing return type for `operator<=>`
JMazurkiewicz b12c9de
Three way comparison got "DeMorganed"
JMazurkiewicz 880b079
Let's do partial specialization on `_Const_assignment` (for @strega-n…
JMazurkiewicz 49b9c17
Merge branch 'main' into tuple_like
JMazurkiewicz bbae2c8
Add parens to restore clang-format.
StephanTLavavej 01bb99c
Fix issues found during mirroring.
StephanTLavavej 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| RUNALL_INCLUDE ..\strict_concepts_latest_matrix.lst | ||
|
JMazurkiewicz marked this conversation as resolved.
|
||
96 changes: 96 additions & 0 deletions
96
tests/std/tests/P2165R4_tuple_like_common_reference/test.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,96 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <array> | ||
| #include <ranges> | ||
| #include <tuple> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| using namespace std; | ||
| using ranges::subrange; | ||
|
|
||
| template <class T, class U> | ||
| concept CanCommonReference = requires { typename common_reference<T, U>::type; }; | ||
|
|
||
| template <class T, class U, class Expected> | ||
| requires CanCommonReference<T, U> | ||
| constexpr bool test_common_reference = | ||
| same_as<common_reference_t<T, U>, Expected> && same_as<common_reference_t<U, T>, Expected>; | ||
|
|
||
| struct Sentinel { | ||
| bool operator==(const auto&) const; // not defined | ||
| operator unreachable_sentinel_t() const; // not defined | ||
| }; | ||
|
|
||
| template <> | ||
| struct std::common_type<Sentinel, unreachable_sentinel_t> { | ||
| using type = unreachable_sentinel_t; | ||
| }; | ||
|
|
||
| template <> | ||
| struct std::common_type<unreachable_sentinel_t, Sentinel> { | ||
| using type = unreachable_sentinel_t; | ||
| }; | ||
|
|
||
| static_assert(test_common_reference<Sentinel, unreachable_sentinel_t, unreachable_sentinel_t>); | ||
|
|
||
| // Test common_reference<tuple, tuple> | ||
| static_assert(test_common_reference<tuple<>, tuple<>, tuple<>>); | ||
| static_assert(test_common_reference<tuple<char&&>, tuple<const int&>, tuple<int>>); | ||
| static_assert(test_common_reference<tuple<int&>, tuple<const int&>, tuple<const int&>>); | ||
| static_assert(test_common_reference<tuple<int&>, tuple<int&&>, tuple<const int&>>); | ||
| static_assert(test_common_reference<tuple<short, int, long>, tuple<long, int, short>, tuple<long, int, long>>); | ||
|
|
||
| // Test common_reference<cvref tuple, cvref tuple> | ||
| static_assert(test_common_reference<tuple<>&, tuple<>&&, const tuple<>&>); | ||
| static_assert( | ||
| test_common_reference<const tuple<int, long>&, volatile tuple<int, long>&, const volatile tuple<int, long>&>); | ||
| static_assert(test_common_reference<tuple<int&, const int&&, volatile int&>&, | ||
| const tuple<const int&, const int, const int&>, tuple<const int&, int, const volatile int&>>); | ||
|
|
||
| // Test common_reference<tuple, tuple-like>, tuple-like is pair | ||
| static_assert(test_common_reference<tuple<int, int>, pair<int, int>, tuple<int, int>>); | ||
| static_assert(test_common_reference<tuple<int, long>, pair<short, long long>, tuple<int, long long>>); | ||
| static_assert( | ||
| test_common_reference<tuple<int&, long&&>, pair<const int&, const long&&>, tuple<const int&, const long&&>>); | ||
| static_assert(test_common_reference<tuple<short&, const volatile long&&>, pair<volatile int, long>, tuple<int, long>>); | ||
|
|
||
| // Test common_reference<cvref tuple, cvref tuple-like>, tuple-like is pair | ||
| static_assert(test_common_reference<tuple<int, int>&, pair<int, int>&, tuple<int&, int&>>); | ||
| static_assert(test_common_reference<const tuple<int, int>&, const pair<int, int>&, tuple<const int&, const int&>>); | ||
| static_assert( | ||
| test_common_reference<tuple<int&, long&&>&, const pair<const int&, const long&&>&, tuple<const int&, const long&>>); | ||
| static_assert(test_common_reference<const tuple<short&, const volatile long&&>, const pair<volatile int, long>&, | ||
| tuple<int, long>>); | ||
|
|
||
| // Test common_reference<tuple, tuple-like>, tuple-like is array | ||
| static_assert(test_common_reference<tuple<>, array<int, 0>, tuple<>>); | ||
| static_assert(test_common_reference<tuple<int>, array<int, 1>, tuple<int>>); | ||
| static_assert(test_common_reference<tuple<int, long>, array<int, 2>, tuple<int, long>>); | ||
| static_assert(test_common_reference<tuple<short, int&&, const long>, array<int, 3>, tuple<int, int, long>>); | ||
| static_assert(test_common_reference<tuple<short&, int&&, const volatile long>, array<int, 3>, tuple<int, int, long>>); | ||
|
|
||
| // Test common_reference<cvref tuple, cvref tuple-like>, tuple-like is array | ||
| static_assert(test_common_reference<const tuple<>&, array<int, 0>, tuple<>>); | ||
| static_assert(test_common_reference<tuple<int>&, array<int, 1>&, tuple<int&>>); | ||
| static_assert(test_common_reference<const tuple<int, long>&&, array<int, 2>&, tuple<const int&, long>>); | ||
|
|
||
| // Test common_reference<tuple, tuple-like>, tuple-like is ranges::subrange | ||
| static_assert(test_common_reference<tuple<int*, int*>, subrange<int*, int*>, tuple<int*, int*>>); | ||
| static_assert( | ||
| test_common_reference<tuple<int*, const int*>, subrange<const int*, int*>, tuple<const int*, const int*>>); | ||
| static_assert(test_common_reference<tuple<int*, Sentinel>, subrange<int*, unreachable_sentinel_t>, | ||
| tuple<int*, unreachable_sentinel_t>>); | ||
| static_assert(test_common_reference<tuple<const volatile int*, Sentinel>, subrange<int*, unreachable_sentinel_t>, | ||
| tuple<const volatile int*, unreachable_sentinel_t>>); | ||
|
|
||
| // Test common_reference<cvref tuple, cvref tuple-like>, tuple-like is ranges::subrange | ||
| static_assert(test_common_reference<const tuple<int*, int*>&&, const subrange<int*, int*>, tuple<int*, int*>>); | ||
| static_assert( | ||
| test_common_reference<const tuple<int*, const int*>&, subrange<const int*, int*>, tuple<const int*, const int*>>); | ||
|
|
||
| // Test invalid common_references | ||
| static_assert(!CanCommonReference<tuple<int>, array<int, 2>>); | ||
| static_assert(!CanCommonReference<tuple<int>, subrange<int*, int*>>); | ||
| static_assert(!CanCommonReference<tuple<int>, pair<int, int>>); |
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,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| RUNALL_INCLUDE ..\concepts_latest_matrix.lst |
88 changes: 88 additions & 0 deletions
88
tests/std/tests/P2165R4_tuple_like_common_type/test.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,88 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| #include <array> | ||
| #include <ranges> | ||
| #include <tuple> | ||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| using namespace std; | ||
| using ranges::subrange; | ||
|
|
||
| template <class T, class U> | ||
| concept CanCommonType = requires { typename common_type<T, U>::type; }; | ||
|
|
||
| template <class T, class U, class Expected> | ||
| requires CanCommonType<T, U> | ||
| inline constexpr bool test_common_type = | ||
| same_as<common_type_t<T, U>, Expected> && same_as<common_type_t<U, T>, Expected>; | ||
|
|
||
| struct Sentinel { | ||
| bool operator==(const auto&) const; // not defined | ||
| operator unreachable_sentinel_t() const; // not defined | ||
| }; | ||
|
|
||
| template <> | ||
| struct std::common_type<Sentinel, unreachable_sentinel_t> { | ||
| using type = unreachable_sentinel_t; | ||
| }; | ||
|
|
||
| template <> | ||
| struct std::common_type<unreachable_sentinel_t, Sentinel> { | ||
| using type = unreachable_sentinel_t; | ||
| }; | ||
|
|
||
| static_assert(test_common_type<Sentinel, unreachable_sentinel_t, unreachable_sentinel_t>); | ||
|
|
||
| // Test common_type<tuple, tuple> | ||
| static_assert(test_common_type<tuple<>, tuple<>, tuple<>>); | ||
| static_assert(test_common_type<tuple<char>, tuple<int>, tuple<int>>); | ||
| static_assert(test_common_type<tuple<int&>, tuple<const int&>, tuple<int>>); | ||
| static_assert(test_common_type<tuple<int&>, tuple<int&&>, tuple<int>>); | ||
| static_assert(test_common_type<tuple<short, long, long>, tuple<long, int, short>, tuple<long, long, long>>); | ||
|
|
||
| // Test common_reference<cvref tuple, cvref tuple> | ||
| static_assert(test_common_type<const tuple<>&, tuple<>&&, tuple<>>); | ||
| static_assert(test_common_type<tuple<char>&, const tuple<int>&&, tuple<int>>); | ||
| static_assert(test_common_type<tuple<int&>&, tuple<const int&>, tuple<int>>); | ||
| static_assert(test_common_type<volatile tuple<int&>&, tuple<int&&>, tuple<int>>); | ||
|
|
||
| // Test common_type<tuple, tuple-like>, tuple-like is pair | ||
| static_assert(test_common_type<tuple<int, int>, pair<int, int>, tuple<int, int>>); | ||
| static_assert(test_common_type<tuple<int, long>, pair<short, long long>, tuple<int, long long>>); | ||
| static_assert(test_common_type<tuple<int&, long&&>, pair<const int&, const long&&>, tuple<int, long>>); | ||
| static_assert(test_common_type<tuple<short&, const volatile long&&>, pair<volatile int, long>, tuple<int, long>>); | ||
|
|
||
| // Test common_type<cvref tuple, cvref tuple-like>, tuple-like is pair | ||
| static_assert(test_common_type<const tuple<int, int>&&, volatile pair<int, int>&, tuple<int, int>>); | ||
| static_assert(test_common_type<volatile tuple<int, long>&&, const pair<short, long long>&&, tuple<int, long long>>); | ||
|
|
||
| // Test common_type<tuple, tuple-like>, tuple-like is array | ||
| static_assert(test_common_type<tuple<>, array<int, 0>, tuple<>>); | ||
| static_assert(test_common_type<tuple<int>, array<int, 1>, tuple<int>>); | ||
| static_assert(test_common_type<tuple<int, long>, array<int, 2>, tuple<int, long>>); | ||
| static_assert(test_common_type<tuple<short, int, long>, array<int, 3>, tuple<int, int, long>>); | ||
| static_assert(test_common_type<tuple<short&, int&&, const volatile long>, array<int, 3>, tuple<int, int, long>>); | ||
|
|
||
| // Test common_type<cvref tuple, cvref tuple-like>, tuple-like is array | ||
| static_assert(test_common_type<const tuple<>&&, volatile array<int, 0>&, tuple<>>); | ||
| static_assert(test_common_type<const tuple<int>&, volatile array<int, 1>&&, tuple<int>>); | ||
|
|
||
| // Test common_type<tuple, tuple-like>, tuple-like is ranges::subrange | ||
| static_assert(test_common_type<tuple<int*, int*>, subrange<int*, int*>, tuple<int*, int*>>); | ||
| static_assert(test_common_type<tuple<int*, const int*>, subrange<const int*, int*>, tuple<const int*, const int*>>); | ||
| static_assert(test_common_type<tuple<int*, Sentinel>, subrange<int*, unreachable_sentinel_t>, | ||
| tuple<int*, unreachable_sentinel_t>>); | ||
| static_assert(test_common_type<tuple<const volatile int*, Sentinel>, subrange<int*, unreachable_sentinel_t>, | ||
| tuple<const volatile int*, unreachable_sentinel_t>>); | ||
|
|
||
| // Test common_type<cvref tuple, cvref tuple-like>, tuple-like is ranges::subrange | ||
| static_assert(test_common_type<const tuple<int*, int*>&, volatile subrange<int*, int*>&&, tuple<int*, int*>>); | ||
| static_assert(test_common_type<volatile tuple<int*, Sentinel>&, const subrange<int*, unreachable_sentinel_t>&&, | ||
| tuple<int*, unreachable_sentinel_t>>); | ||
|
|
||
| // Test invalid common_types | ||
| static_assert(!CanCommonType<tuple<int>, array<int, 2>>); | ||
| static_assert(!CanCommonType<tuple<int>, subrange<int*, int*>>); | ||
| static_assert(!CanCommonType<tuple<int>, pair<int, int>>); |
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,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| RUNALL_INCLUDE ..\concepts_latest_matrix.lst |
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.
Uh oh!
There was an error while loading. Please reload this page.