[libcxx-commits] [libcxx] 706b395 - [libc++] Implement `operator==` for `filesystem::space_info`

Adrian Vogelsgesang via libcxx-commits libcxx-commits at lists.llvm.org
Mon Aug 8 10:07:13 PDT 2022


Author: Adrian Vogelsgesang
Date: 2022-08-08T10:05:47-07:00
New Revision: 706b3951b38961ffa6581d446fee6664038caced

URL: https://github.com/llvm/llvm-project/commit/706b3951b38961ffa6581d446fee6664038caced
DIFF: https://github.com/llvm/llvm-project/commit/706b3951b38961ffa6581d446fee6664038caced.diff

LOG: [libc++] Implement `operator==` for `filesystem::space_info`

Implements part of P1614R2 "The Mothership has Landed"

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

Added: 
    libcxx/test/std/input.output/filesystems/fs.filesystem.synopsis/space_info.pass.cpp

Modified: 
    libcxx/docs/Status/SpaceshipProjects.csv
    libcxx/include/__filesystem/space_info.h
    libcxx/include/filesystem

Removed: 
    


################################################################################
diff  --git a/libcxx/docs/Status/SpaceshipProjects.csv b/libcxx/docs/Status/SpaceshipProjects.csv
index 8ba48bdf7c39e..4ef0ca92a82b0 100644
--- a/libcxx/docs/Status/SpaceshipProjects.csv
+++ b/libcxx/docs/Status/SpaceshipProjects.csv
@@ -74,7 +74,7 @@ Section,Description,Dependencies,Assignee,Complete
 | `[time.zone.link.nonmembers] <https://wg21.link/time.zone.link.nonmembers>`_","| chrono::time_zone
 | chrono::leap_second
 | chrono::time_zone_link",A ``<chrono>`` implementation,Unassigned,|Not Started|
-| `[fs.filesystem.syn] <https://wg21.link/fs.filesystem.syn>`_,| `filesystem::space_info <https://reviews.llvm.org/D130861>`_,None,Adrian Vogelsgesang,|In Progress|
+| `[fs.filesystem.syn] <https://wg21.link/fs.filesystem.syn>`_,| `filesystem::space_info <https://reviews.llvm.org/D130861>`_,None,Adrian Vogelsgesang,|Complete|
 | `[fs.path.nonmember] <https://wg21.link/fs.path.nonmember>`_,| `filesystem::path <https://reviews.llvm.org/D130859>`_,None,Adrian Vogelsgesang,|In Progress|
 | `[fs.dir.entry.obs] <https://wg21.link/fs.dir.entry.obs>`_,| `filesystem::directory_entry <https://reviews.llvm.org/D130860>`_,None,Adrian Vogelsgesang,|In Progress|
 | `[re.submatch.op] <https://wg21.link/re.submatch.op>`_,| sub_match,None,Mark de Wever,|In Progress|

diff  --git a/libcxx/include/__filesystem/space_info.h b/libcxx/include/__filesystem/space_info.h
index d7dc03af75a7f..d0747e35ebf02 100644
--- a/libcxx/include/__filesystem/space_info.h
+++ b/libcxx/include/__filesystem/space_info.h
@@ -28,6 +28,10 @@ struct _LIBCPP_TYPE_VIS space_info {
   uintmax_t capacity;
   uintmax_t free;
   uintmax_t available;
+
+#  if _LIBCPP_STD_VER > 17
+  friend _LIBCPP_HIDE_FROM_ABI bool operator==(const space_info&, const space_info&) = default;
+#  endif
 };
 
 _LIBCPP_AVAILABILITY_FILESYSTEM_POP

diff  --git a/libcxx/include/filesystem b/libcxx/include/filesystem
index 87de8861ea422..aa0cd562e2afb 100644
--- a/libcxx/include/filesystem
+++ b/libcxx/include/filesystem
@@ -64,6 +64,8 @@
       uintmax_t capacity;
       uintmax_t free;
       uintmax_t available;
+
+      friend bool operator==(const space_info&, const space_info&) = default; // C++20
     };
 
     enum class file_type;

diff  --git a/libcxx/test/std/input.output/filesystems/fs.filesystem.synopsis/space_info.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.filesystem.synopsis/space_info.pass.cpp
new file mode 100644
index 0000000000000..9a9a93c3c9847
--- /dev/null
+++ b/libcxx/test/std/input.output/filesystems/fs.filesystem.synopsis/space_info.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <filesystem>
+
+// friend bool operator==(const space_info&, const space_info&);
+
+#include "filesystem_include.h"
+
+#include "test_macros.h"
+#include "test_comparisons.h"
+
+using namespace fs;
+
+constexpr bool test() {
+  assert(testEquality(space_info{1, 2, 3}, space_info{1, 2, 3}, true));
+  assert(testEquality(space_info{0, 2, 3}, space_info{1, 2, 3}, false));
+  assert(testEquality(space_info{1, 0, 3}, space_info{1, 2, 3}, false));
+  assert(testEquality(space_info{1, 2, 0}, space_info{1, 2, 3}, false));
+
+  return true;
+}
+
+int main(int, char**) {
+  using space_info = std::filesystem::space_info;
+
+  AssertEqualityAreNoexcept<space_info>();
+  AssertEqualityReturnBool<space_info>();
+
+  test();
+  static_assert(test());
+
+  return 0;
+}


        


More information about the libcxx-commits mailing list