[libcxx-commits] [PATCH] D69344: [libcxx] Add move constructor to compressed pair
Zoe Carver via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 23 09:28:22 PDT 2019
zoecarver created this revision.
zoecarver added reviewers: ldionne, EricWF, mclow.lists.
Herald added subscribers: libcxx-commits, dexonsmith, christof.
Herald added a project: libc++.
zoecarver updated this revision to Diff 226153.
zoecarver added a comment.
- remove unnecessary template
This patch adds a move constructor to `__compressed_pair` so that move-only elements of nested compressed pairs (such as a move-only deleter in a `std::shared_ptr`) can be move-constructed.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D69344
Files:
libcxx/include/memory
libcxx/test/libcxx/utilities/compressed_pair/move_const.pass.cpp
Index: libcxx/test/libcxx/utilities/compressed_pair/move_const.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/libcxx/utilities/compressed_pair/move_const.pass.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+#include <memory>
+
+#include "test_macros.h"
+
+struct NoCopy {
+ NoCopy(NoCopy const&) = delete;
+ NoCopy() = delete;
+ explicit NoCopy(int) {}
+
+ NoCopy(NoCopy &&) = default;
+};
+
+template<class T>
+struct Foo {
+ std::__compressed_pair<std::__compressed_pair<NoCopy, int>, int> x;
+ Foo(T t, int i) : x(std::__compressed_pair<NoCopy, int>(std::move(t), i), 0) {}
+};
+
+int main(int, char**)
+{
+ Foo<NoCopy> f(NoCopy(0), 1);
+
+ return 0;
+}
\ No newline at end of file
Index: libcxx/include/memory
===================================================================
--- libcxx/include/memory
+++ libcxx/include/memory
@@ -2314,6 +2314,11 @@
: _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
#endif
+ _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
+ __compressed_pair(__compressed_pair && __other)
+ : _Base1(_VSTD::move(__other.first())), _Base2(_VSTD::move(__other.second()))
+ {}
+
_LIBCPP_INLINE_VISIBILITY
typename _Base1::reference first() _NOEXCEPT {
return static_cast<_Base1&>(*this).__get();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69344.226153.patch
Type: text/x-patch
Size: 1712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20191023/081c3582/attachment.bin>
More information about the libcxx-commits
mailing list