[libc++] Adds (to|from)_chars_result operator==.
authorMark de Wever <koraq@xs4all.nl>
Sat, 23 Oct 2021 16:28:31 +0000 (18:28 +0200)
committerMark de Wever <koraq@xs4all.nl>
Fri, 19 Nov 2021 15:29:33 +0000 (16:29 +0100)
Implements part of P1614 The Mothership has Landed.

Reviewed By: #libc, Quuxplusone, Mordante

Differential Revision: https://reviews.llvm.org/D112366

libcxx/docs/Status/SpaceshipProjects.csv
libcxx/include/__charconv/from_chars_result.h
libcxx/include/__charconv/to_chars_result.h
libcxx/include/charconv
libcxx/test/std/utilities/charconv/charconv.syn/from_chars_result.pass.cpp [new file with mode: 0644]
libcxx/test/std/utilities/charconv/charconv.syn/to_chars_result.pass.cpp [new file with mode: 0644]

index eed4a47..a789a6c 100644 (file)
@@ -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|
index 6d289ba..fbd7d50 100644 (file)
@@ -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
index b610a6a..f515ee3 100644 (file)
@@ -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
index ee21584..3c969dc 100644 (file)
@@ -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 (file)
index 0000000..007446b
--- /dev/null
@@ -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 (file)
index 0000000..2320f91
--- /dev/null
@@ -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;
+}