-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libcxx] Put std::monostate in <utility>
#128373
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
AmrDeveloper
merged 15 commits into
llvm:main
from
AmrDeveloper:put_monostate_in_utility
Mar 25, 2025
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
56d0405
[libcxx] Put `std::monostate` in `<utility>`
AmrDeveloper 4217fd7
Add utility/monostate.h to cmakelist
AmrDeveloper 95d12dc
Fix hyperlink in release note
AmrDeveloper 1f4fb8c
Replace doublicate monostate by include it in utility
AmrDeveloper 0255bb1
Remove building files
AmrDeveloper 6ffa308
Format the macro endif
AmrDeveloper 381d9a6
Format the code
AmrDeveloper 2ec2815
Add utility cstring to cxx26.csv
AmrDeveloper 7136158
Add experimental/utility cstring to cxx26.csv
AmrDeveloper a526ba6
Enable moving monostate from C++17
AmrDeveloper 4201028
Add tuple cstring to Cxx 17 and 20
AmrDeveloper 1f90241
typeindex cstring for cxx 17, 20
AmrDeveloper 7ee3ea6
Put std::monostate in C++26 and above
AmrDeveloper d6db25a
Merge branch 'main' into put_monostate_in_utility
AmrDeveloper 9a24af3
Update the test requirements to target C++26
AmrDeveloper 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
47 changes: 47 additions & 0 deletions
47
libcxx/test/std/utilities/utility/utility.monostate.relpos/relops.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,47 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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++17 | ||
|
|
||
| // <utility> | ||
|
|
||
| // constexpr bool operator<(monostate, monostate) noexcept { return false; } | ||
| // constexpr bool operator>(monostate, monostate) noexcept { return false; } | ||
| // constexpr bool operator<=(monostate, monostate) noexcept { return true; } | ||
| // constexpr bool operator>=(monostate, monostate) noexcept { return true; } | ||
| // constexpr bool operator==(monostate, monostate) noexcept { return true; } | ||
| // constexpr bool operator!=(monostate, monostate) noexcept { return false; } | ||
| // constexpr strong_ordering operator<=>(monostate, monostate) noexcept { return strong_ordering::equal; } // since C++20 | ||
|
|
||
| #include <cassert> | ||
| #include <utility> | ||
|
|
||
| #include "test_comparisons.h" | ||
| #include "test_macros.h" | ||
|
|
||
| constexpr bool test() { | ||
| using M = std::monostate; | ||
| constexpr M m1{}; | ||
| constexpr M m2{}; | ||
| assert(testComparisons(m1, m2, /*isEqual*/ true, /*isLess*/ false)); | ||
| AssertComparisonsAreNoexcept<M>(); | ||
|
|
||
| #if TEST_STD_VER > 17 | ||
| assert(testOrder(m1, m2, std::strong_ordering::equal)); | ||
| AssertOrderAreNoexcept<M>(); | ||
| #endif // TEST_STD_VER > 17 | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| int main(int, char**) { | ||
| test(); | ||
| static_assert(test()); | ||
|
|
||
| return 0; | ||
| } |
31 changes: 31 additions & 0 deletions
31
libcxx/test/std/utilities/utility/utility.monostate/monostate.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,31 @@ | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // 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++17 | ||
|
|
||
| // <utility> | ||
|
|
||
| // struct monostate {}; | ||
|
|
||
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| #include "test_macros.h" | ||
|
|
||
| int main(int, char**) { | ||
| using M = std::monostate; | ||
| static_assert(std::is_trivially_default_constructible<M>::value, ""); | ||
| static_assert(std::is_trivially_copy_constructible<M>::value, ""); | ||
| static_assert(std::is_trivially_copy_assignable<M>::value, ""); | ||
| static_assert(std::is_trivially_destructible<M>::value, ""); | ||
| constexpr M m{}; | ||
| ((void)m); | ||
|
|
||
| return 0; | ||
| } |
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.
That this adds new dependencies is a bit unexpected to me. I thought that we already had
std::hashin<utility>, but that we didn't makes me think we shouldn't back-port this after all.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.
Yes i think it's not that problem to support from Cxx17
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.
Oh... libc++'s
<utility>used to providestd::hash, but such extension (?) was removed by 69d5a66 (https://reviews.llvm.org/D104002).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.
Should we keep the dependencies or just support from C++26 🤔 @frederick-vs-ja @philnik777
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.
Let's only add it in C++26 for now. It's much easier to add features than to remove them.