Skip to content

Commit 3573065

Browse files
authored
[libcxx] Put std::monostate in <utility> (#128373)
Fixes: #127874
1 parent 2593838 commit 3573065

File tree

6 files changed

+86
-1
lines changed

6 files changed

+86
-1
lines changed

libcxx/docs/ReleaseNotes/21.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Implemented Papers
4444
- P2255R2: A type trait to detect reference binding to temporary (implemented the type traits only) (`Github <https://github.com/llvm/llvm-project/issues/105180>`__)
4545
- P2562R1: ``constexpr`` Stable Sorting (`Github <https://github.com/llvm/llvm-project/issues/105360>`__)
4646
- P1222R4: A Standard ``flat_set`` is partially implemented and ``flat_set`` is provided (`Github <https://github.com/llvm/llvm-project/issues/105193>`__)
47+
- P0472R3: Put std::monostate in <utility> (`Github <https://github.com/llvm/llvm-project/issues/127874>`__)
4748

4849
Improvements and New Features
4950
-----------------------------

libcxx/docs/Status/Cxx2cPapers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"`P3475R2 <https://wg21.link/P3475R2>`__","Defang and deprecate ``memory_order::consume``","2025-02 (Hagenberg)","","",""
103103
"`P2786R13 <https://wg21.link/P2786R13>`__","Trivial Relocatability For C++26","2025-02 (Hagenberg)","","",""
104104
"`P3137R3 <https://wg21.link/P3137R3>`__","``views::to_input``","2025-02 (Hagenberg)","","",""
105-
"`P0472R3 <https://wg21.link/P0472R3>`__","Put ``std::monostate`` in ``<utility>``","2025-02 (Hagenberg)","","",""
105+
"`P0472R3 <https://wg21.link/P0472R3>`__","Put ``std::monostate`` in ``<utility>``","2025-02 (Hagenberg)","|Complete|","21",""
106106
"`P3349R1 <https://wg21.link/P3349R1>`__","Converting contiguous iterators to pointers","2025-02 (Hagenberg)","","",""
107107
"`P3372R3 <https://wg21.link/P3372R3>`__","constexpr containers and adaptors","2025-02 (Hagenberg)","","",""
108108
"`P3378R2 <https://wg21.link/P3378R2>`__","constexpr exception types","2025-02 (Hagenberg)","","",""

libcxx/include/utility

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ template <class T>
279279
# include <__utility/unreachable.h>
280280
# endif
281281

282+
# if _LIBCPP_STD_VER >= 26
283+
# include <__variant/monostate.h>
284+
# endif
285+
282286
# include <version>
283287

284288
// standard-mandated includes

libcxx/test/libcxx/transitive_includes/cxx26.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ experimental/type_traits type_traits
301301
experimental/type_traits version
302302
experimental/utility compare
303303
experimental/utility cstdint
304+
experimental/utility cstring
304305
experimental/utility initializer_list
305306
experimental/utility limits
306307
experimental/utility utility
@@ -1127,6 +1128,7 @@ unordered_set tuple
11271128
unordered_set version
11281129
utility compare
11291130
utility cstdint
1131+
utility cstring
11301132
utility initializer_list
11311133
utility limits
11321134
utility version
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++26
10+
11+
// <utility>
12+
13+
// constexpr bool operator<(monostate, monostate) noexcept { return false; }
14+
// constexpr bool operator>(monostate, monostate) noexcept { return false; }
15+
// constexpr bool operator<=(monostate, monostate) noexcept { return true; }
16+
// constexpr bool operator>=(monostate, monostate) noexcept { return true; }
17+
// constexpr bool operator==(monostate, monostate) noexcept { return true; }
18+
// constexpr bool operator!=(monostate, monostate) noexcept { return false; }
19+
// constexpr strong_ordering operator<=>(monostate, monostate) noexcept { return strong_ordering::equal; } // since C++20
20+
21+
#include <cassert>
22+
#include <utility>
23+
24+
#include "test_comparisons.h"
25+
#include "test_macros.h"
26+
27+
constexpr bool test() {
28+
using M = std::monostate;
29+
constexpr M m1{};
30+
constexpr M m2{};
31+
assert(testComparisons(m1, m2, /*isEqual*/ true, /*isLess*/ false));
32+
AssertComparisonsAreNoexcept<M>();
33+
34+
#if TEST_STD_VER > 17
35+
assert(testOrder(m1, m2, std::strong_ordering::equal));
36+
AssertOrderAreNoexcept<M>();
37+
#endif // TEST_STD_VER > 17
38+
39+
return true;
40+
}
41+
42+
int main(int, char**) {
43+
test();
44+
static_assert(test());
45+
46+
return 0;
47+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
// REQUIRES: std-at-least-c++26
11+
12+
// <utility>
13+
14+
// struct monostate {};
15+
16+
#include <type_traits>
17+
#include <utility>
18+
19+
#include "test_macros.h"
20+
21+
int main(int, char**) {
22+
using M = std::monostate;
23+
static_assert(std::is_trivially_default_constructible<M>::value, "");
24+
static_assert(std::is_trivially_copy_constructible<M>::value, "");
25+
static_assert(std::is_trivially_copy_assignable<M>::value, "");
26+
static_assert(std::is_trivially_destructible<M>::value, "");
27+
constexpr M m{};
28+
((void)m);
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)