[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
This commit is contained in:
Mark de Wever 2021-10-23 18:28:31 +02:00
parent 4c94760f36
commit 3624c4d845
6 changed files with 96 additions and 0 deletions

View 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|

1 Section Description Dependencies Assignee Complete
25 | `[list.syn] <https://wg21.link/list.syn>`_ (`general <https://wg21.link/container.requirements.general#14>`_) | `[deque.syn] <https://wg21.link/deque.syn>`_ (`general <https://wg21.link/container.requirements.general#14>`_) | list | deque [expos.only.func] Unassigned |Not Started|
26 | `[vector.syn] <https://wg21.link/vector.syn>`_ (`general <https://wg21.link/container.requirements.general#14>`_) | `[forward.list.syn] <https://wg21.link/forward.list.syn>`_ (`general <https://wg21.link/container.requirements.general#14>`_) | vector | forward_list [expos.only.func] Unassigned |Not Started|
27 | `[associative.map.syn] <https://wg21.link/associative.map.syn>`_ (`general <https://wg21.link/container.requirements.general#14>`_) | `[list.syn] <https://wg21.link/list.syn>`_ (`general <https://wg21.link/container.requirements.general#14>`_) | map | multimap | list [expos.only.func] Unassigned |Not Started|
28 | `[vector.syn] <https://wg21.link/vector.syn>`_ (`general <https://wg21.link/container.requirements.general#14>`_) | vector [expos.only.func] Unassigned |Not Started|
29 | `[associative.map.syn] <https://wg21.link/associative.map.syn>`_ (`general <https://wg21.link/container.requirements.general#14>`_) | map | multimap [expos.only.func] Unassigned |Not Started|
30 | `[associative.set.syn] <https://wg21.link/associative.set.syn>`_ (`general <https://wg21.link/container.requirements.general#14>`_) | multiset | set [expos.only.func] Unassigned |Not Started|
31 | `[queue.ops] <https://wg21.link/queue.ops>`_ | queue None Unassigned |Not Started|
32 | `[stack.ops] <https://wg21.link/stack.ops>`_ | stack None Unassigned |Not Started|

View 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

View 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

View 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,

View File

@ -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;
}

View File

@ -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;
}