[libcxx-commits] [PATCH] D152617: [libc++][spaceship] P1614R2: Added `operator==` to `slice`
Hristo Hristov via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jun 10 04:00:00 PDT 2023
H-G-Hristov created this revision.
Herald added a subscriber: yaxunl.
Herald added a project: All.
H-G-Hristov requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Implements parts of P1614R2:
- Added `operator==` to `slice`
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D152617
Files:
libcxx/include/valarray
libcxx/test/std/numerics/numarray/class.slice/slice.ops/slice.ops.pass.cpp
Index: libcxx/test/std/numerics/numarray/class.slice/slice.ops/slice.ops.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/numerics/numarray/class.slice/slice.ops/slice.ops.pass.cpp
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <valarray>
+
+// class slice;
+
+// friend bool operator==(const slice& x, const slice& y);
+
+#include <valarray>
+#include <cassert>
+
+int main(int, char**) {
+ {
+ std::slice s1;
+ std::slice s2;
+
+ assert(s1 == s2);
+ assert(s2 == s1);
+ }
+ {
+ std::slice s1(1, 2, 3);
+ std::slice s2{1, 2, 3};
+
+ assert(s1 == s2);
+ assert(s2 == s1);
+ }
+ {
+ std::slice s1(0, 2, 3);
+ std::slice s2{1, 2, 3};
+
+ assert(s1 != s2);
+ assert(s2 != s1);
+ }
+ {
+ std::slice s1(1, 0, 3);
+ std::slice s2{1, 2, 3};
+
+ assert(s1 != s2);
+ assert(s2 != s1);
+ }
+ {
+ std::slice s1(1, 2, 0);
+ std::slice s2{1, 2, 3};
+
+ assert(s1 != s2);
+ assert(s2 != s1);
+ }
+
+ return 0;
+}
Index: libcxx/include/valarray
===================================================================
--- libcxx/include/valarray
+++ libcxx/include/valarray
@@ -402,8 +402,24 @@
_LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
_LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
_LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
+
+#if _LIBCPP_STD_VER >= 20
+
+ friend bool operator==(const slice& __x, const slice& __y);
+
+#endif
};
+#if _LIBCPP_STD_VER >= 20
+
+bool operator==(const slice& __x, const slice& __y)
+{
+ return __x.start() == __y.start() && __x.size() == __y.size() && __x.stride() == __y.stride();
+}
+
+#endif
+
+
template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array;
class _LIBCPP_TYPE_VIS gslice;
template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152617.530192.patch
Type: text/x-patch
Size: 2245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230610/bcf7444b/attachment.bin>
More information about the libcxx-commits
mailing list