[libcxx-commits] [libcxx] 3624c4d - [libc++] Adds (to|from)_chars_result operator==.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Nov 19 07:29:38 PST 2021
Author: Mark de Wever
Date: 2021-11-19T16:29:33+01:00
New Revision: 3624c4d84500e52ec1fa5ac72502693129bae715
URL: https://github.com/llvm/llvm-project/commit/3624c4d84500e52ec1fa5ac72502693129bae715
DIFF: https://github.com/llvm/llvm-project/commit/3624c4d84500e52ec1fa5ac72502693129bae715.diff
LOG: [libc++] Adds (to|from)_chars_result operator==.
Implements part of P1614 The Mothership has Landed.
Reviewed By: #libc, Quuxplusone, Mordante
Differential Revision: https://reviews.llvm.org/D112366
Added:
libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.pass.cpp
libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.pass.cpp
Modified:
libcxx/docs/Status/SpaceshipProjects.csv
libcxx/include/__charconv/from_chars_result.h
libcxx/include/__charconv/to_chars_result.h
libcxx/include/charconv
Removed:
################################################################################
diff --git a/libcxx/docs/Status/SpaceshipProjects.csv b/libcxx/docs/Status/SpaceshipProjects.csv
index eed4a47227318..a789a6cfd3027 100644
--- a/libcxx/docs/Status/SpaceshipProjects.csv
+++ b/libcxx/docs/Status/SpaceshipProjects.csv
@@ -25,6 +25,8 @@ Section,Description,Dependencies,Assignee,Complete
| `[unique.ptr.special] <https://wg21.link/unique.ptr.special>`_,| unique_ptr,[comparisons.three.way],Unassigned,|Not Started|
| `[util.smartptr.shared.cmp] <https://wg21.link/util.smartptr.shared.cmp>`_,| shared_ptr,[comparisons.three.way],Unassigned,|Not Started|
| `[type.index.members] <https://wg21.link/type.index.members>`_,| type_index,None,Unassigned,|Not Started|
+| `[charconv.syn] <https://wg21.link/charconv.syn>`_,| to_chars_result,None,Mark de Wever,|Complete|
+| `[charconv.syn] <https://wg21.link/charconv.syn>`_,| from_chars_result,None,Mark de Wever,|Complete|
| `[stacktrace.entry.cmp] <https://wg21.link/stacktrace.entry.cmp>`_,| stacktrace_entry,None,Unassigned,|Not Started|
| `[stacktrace.basic.cmp] <https://wg21.link/stacktrace.basic.cmp>`_,| basic_stacktrace,[alg.three.way],Unassigned,|Not Started|
| `[string.cmp] <https://wg21.link/string.cmp>`_,| `basic_string <https://reviews.llvm.org/D80895>`_,None,Christopher Di Bella,|In Progress|
diff --git a/libcxx/include/__charconv/from_chars_result.h b/libcxx/include/__charconv/from_chars_result.h
index 6d289ba79fd5a..fbd7d508115f6 100644
--- a/libcxx/include/__charconv/from_chars_result.h
+++ b/libcxx/include/__charconv/from_chars_result.h
@@ -25,6 +25,9 @@ struct _LIBCPP_TYPE_VIS from_chars_result
{
const char* ptr;
errc ec;
+# if _LIBCPP_STD_VER > 17
+ _LIBCPP_HIDE_FROM_ABI friend bool operator==(const from_chars_result&, const from_chars_result&) = default;
+# endif
};
#endif // _LIBCPP_CXX03_LANG
diff --git a/libcxx/include/__charconv/to_chars_result.h b/libcxx/include/__charconv/to_chars_result.h
index b610a6adcfb42..f515ee3122c1a 100644
--- a/libcxx/include/__charconv/to_chars_result.h
+++ b/libcxx/include/__charconv/to_chars_result.h
@@ -25,6 +25,9 @@ struct _LIBCPP_TYPE_VIS to_chars_result
{
char* ptr;
errc ec;
+# if _LIBCPP_STD_VER > 17
+ _LIBCPP_HIDE_FROM_ABI friend bool operator==(const to_chars_result&, const to_chars_result&) = default;
+# endif
};
#endif // _LIBCPP_CXX03_LANG
diff --git a/libcxx/include/charconv b/libcxx/include/charconv
index ee215840f53f5..3c969dc79ab06 100644
--- a/libcxx/include/charconv
+++ b/libcxx/include/charconv
@@ -27,6 +27,7 @@ namespace std {
struct to_chars_result {
char* ptr;
errc ec;
+ friend bool operator==(const to_chars_result&, const to_chars_result&) = default; // since C++20
};
to_chars_result to_chars(char* first, char* last, see below value,
@@ -56,6 +57,7 @@ namespace std {
struct from_chars_result {
const char* ptr;
errc ec;
+ friend bool operator==(const from_chars_result&, const from_chars_result&) = default; // since C++20
};
from_chars_result from_chars(const char* first, const char* last,
diff --git a/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.pass.cpp b/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.pass.cpp
new file mode 100644
index 0000000000000..007446b3f03a2
--- /dev/null
+++ b/libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.pass.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-no-concepts
+
+// <charconv>
+
+// struct from_chars_result
+// friend bool operator==(const from_chars_result&, const from_chars_result&) = default;
+
+#include <charconv>
+
+#include <cassert>
+#include <compare>
+#include <concepts>
+
+#include "test_macros.h"
+
+constexpr bool test() {
+ std::from_chars_result lhs{nullptr, std::errc{}};
+ std::from_chars_result rhs{nullptr, std::errc{}};
+ assert(lhs == rhs);
+ assert(!(lhs != rhs));
+
+ return true;
+}
+
+int main(int, char**) {
+ static_assert(std::equality_comparable<std::from_chars_result>);
+ static_assert(!std::totally_ordered<std::from_chars_result>);
+ static_assert(!std::three_way_comparable<std::from_chars_result>);
+
+ assert(test());
+ static_assert(test());
+
+ return 0;
+}
diff --git a/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.pass.cpp b/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.pass.cpp
new file mode 100644
index 0000000000000..2320f917f8254
--- /dev/null
+++ b/libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.pass.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+// UNSUPPORTED: libcpp-no-concepts
+
+// <charconv>
+
+// struct to_chars_result
+// friend bool operator==(const to_chars_result&, const to_chars_result&) = default;
+
+#include <charconv>
+
+#include <cassert>
+#include <compare>
+#include <concepts>
+
+#include "test_macros.h"
+
+constexpr bool test() {
+ std::to_chars_result lhs{nullptr, std::errc{}};
+ std::to_chars_result rhs{nullptr, std::errc{}};
+ assert(lhs == rhs);
+ assert(!(lhs != rhs));
+
+ return true;
+}
+
+int main(int, char**) {
+ static_assert(std::equality_comparable<std::to_chars_result>);
+ static_assert(!std::totally_ordered<std::to_chars_result>);
+ static_assert(!std::three_way_comparable<std::to_chars_result>);
+
+ assert(test());
+ static_assert(test());
+
+ return 0;
+}
More information about the libcxx-commits
mailing list