summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2017-11-27 15:51:36 +0000
committerMarshall Clow <mclow.lists@gmail.com>2017-11-27 15:51:36 +0000
commitb25029437e2141fc74062d8331f3c355bfdfe0f6 (patch)
treeb9476bdb46cfc8c940b62c92f6e61c13a7214a5e
parentc72032be6013dd0507fff2c29835f214aae631e3 (diff)
Implement LWG#2948: unique_ptr does not define operator<< for stream output
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@319038 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/memory3
-rw-r--r--include/ostream12
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp31
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.special/io.pass.cpp29
-rw-r--r--www/cxx2a_status.html4
5 files changed, 77 insertions, 2 deletions
diff --git a/include/memory b/include/memory
index 30cb79eb5..5c109df1c 100644
--- a/include/memory
+++ b/include/memory
@@ -387,6 +387,9 @@ template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args);
template<class T> unique_ptr<T> make_unique(size_t n); // C++14
template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
+template<class E, class T, class Y, class D>
+ basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p);
+
template<class T>
class shared_ptr
{
diff --git a/include/ostream b/include/ostream
index 9bf8d3cdc..92f7f4dfb 100644
--- a/include/ostream
+++ b/include/ostream
@@ -1071,6 +1071,18 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p)
return __os << __p.get();
}
+template<class _CharT, class _Traits, class _Yp, class _Dp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if
+<
+ is_same<void, typename __void_t<decltype(declval<basic_ostream<_CharT, _Traits>&>() << declval<_Yp>())>::type>::value,
+ basic_ostream<_CharT, _Traits>&
+>::type
+operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)
+{
+ return __os << __p.get();
+}
+
template <class _CharT, class _Traits, size_t _Size>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp
new file mode 100644
index 000000000..1a4c0bd82
--- /dev/null
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.fail.cpp
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// template<class CharT, class Traits, class Y, class D>
+// basic_ostream<CharT, Traits>&
+// operator<<(basic_ostream<CharT, Traits>& os, const unique_ptr<Y, D>& p);
+
+// -?- Remarks: This function shall not participate in overload resolution unless os << p.get() is a valid expression.
+
+#include <memory>
+#include <sstream>
+#include <cassert>
+
+class A {};
+
+int main()
+{
+ std::unique_ptr<A> p(new A);
+ std::ostringstream os;
+ os << p;
+}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.pass.cpp
new file mode 100644
index 000000000..81a1c368a
--- /dev/null
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.special/io.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <memory>
+
+// unique_ptr
+
+// template<class CharT, class Traits, class Y, class D>
+// basic_ostream<CharT, Traits>&
+// operator<<(basic_ostream<CharT, Traits>& os, const unique_ptr<Y, D>& p);
+
+#include <memory>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+ std::unique_ptr<int> p(new int(3));
+ std::ostringstream os;
+ assert(os.str().empty());
+ os << p;
+ assert(!os.str().empty());
+}
diff --git a/www/cxx2a_status.html b/www/cxx2a_status.html
index 3a2a66d58..d7b584c19 100644
--- a/www/cxx2a_status.html
+++ b/www/cxx2a_status.html
@@ -65,7 +65,7 @@
<tr><td><a href="https://wg21.link/P0439R0">P0439R0</a></td><td>LWG</td><td>Make <tt>std::memory_order</tt> a scoped enumeration</td><td>Albuquerque</td><td></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0457R2">P0457R2</a></td><td>LWG</td><td>String Prefix and Suffix Checking</td><td>Albuquerque</td><td></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0550R2">P0550R2</a></td><td>LWG</td><td>Transformation Trait <tt>remove_cvref</tt></td><td>Albuquerque</td><td>Complete</td><td>6.0</td></tr>
- <tr><td><a href="https://wg21.link/P0600R1">P0600R1</a></td><td>LWG</td><td>nodiscard in the Library</td><td>Albuquerque</td><td></td><td></td></tr>
+ <tr><td><a href="https://wg21.link/P0600R1">P0600R1</a></td><td>LWG</td><td>nodiscard in the Library</td><td>Albuquerque</td><td><I>In Progress</I></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0616R0">P0616R0</a></td><td>LWG</td><td>de-pessimize legacy <numeric> algorithms with std::move</td><td>Albuquerque</td><td></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0653R2">P0653R2</a></td><td>LWG</td><td>Utility to convert a pointer to a raw pointer</td><td>Albuquerque</td><td>Complete</td><td>6.0</td></tr>
<tr><td><a href="https://wg21.link/P0718R2">P0718R2</a></td><td>LWG</td><td>Atomic shared_ptr</td><td>Albuquerque</td><td></td><td></td></tr>
@@ -106,7 +106,7 @@
<tr><td><a href="https://wg21.link/LWG2941">2941</a></td><td>[thread.req.timing] wording should apply to both member and namespace-level functions</td><td>Albuquerque</td><td><i>Nothing to do</i></td></tr>
<tr><td><a href="https://wg21.link/LWG2944">2944</a></td><td>LWG 2905 accidentally removed requirement that construction of the deleter doesn't throw an exception</td><td>Albuquerque</td><td><i>Nothing to do</i></td></tr>
<tr><td><a href="https://wg21.link/LWG2945">2945</a></td><td>Order of template parameters in optional comparisons</td><td>Albuquerque</td><td>Complete</td></tr>
- <tr><td><a href="https://wg21.link/LWG2948">2948</a></td><td>unique_ptr does not define operator<< for stream output</td><td>Albuquerque</td><td></td></tr>
+ <tr><td><a href="https://wg21.link/LWG2948">2948</a></td><td>unique_ptr does not define operator<< for stream output</td><td>Albuquerque</td><td>Complete</td></tr>
<tr><td><a href="https://wg21.link/LWG2950">2950</a></td><td>std::byte operations are misspecified</td><td>Albuquerque</td><td>Complete</td></tr>
<tr><td><a href="https://wg21.link/LWG2952">2952</a></td><td>iterator_traits should work for pointers to cv T</td><td>Albuquerque</td><td>Complete</td></tr>
<tr><td><a href="https://wg21.link/LWG2953">2953</a></td><td>LWG 2853 should apply to deque::erase too</td><td>Albuquerque</td><td></td></tr>