[v3 PATCH] Implement 2801, Default-constructibility of unique_ptr.

Jonathan Wakely jwakely@redhat.com
Thu Dec 22 17:11:00 GMT 2016


On 20/12/16 22:52 +0200, Ville Voutilainen wrote:
>diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h
>index 56e6ec0..63dff37 100644
>--- a/libstdc++-v3/include/bits/unique_ptr.h
>+++ b/libstdc++-v3/include/bits/unique_ptr.h
>@@ -175,10 +175,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>       // Constructors.
>
>       /// Default constructor, creates a unique_ptr that owns nothing.
>+      template <typename _Up = deleter_type,
>+		typename enable_if<
>+		  __and_<__not_<is_pointer<_Up>>,
>+			 is_default_constructible<_Up>>::value,
>+		  bool>::type = false>

Instead of repeating this condition half a dozen times, we could put
it in the __uniq_ptr_impl class template and reuse it, as in the
attached patch (and similarly for the unique_ptr<t[]> specialization).
What do you think?

>       constexpr unique_ptr() noexcept
>       : _M_t()
>-      { static_assert(!is_pointer<deleter_type>::value,
>-		     "constructed with null function pointer deleter"); }
>+      { }

The bodies of these constructors should be indented now that they're
templates.


>--- /dev/null
>+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/default.cc
>@@ -0,0 +1,40 @@
>+// { dg-do compile { target c++11 } }
>+
>+// Copyright (C) 2011-2016 Free Software Foundation, Inc.

Is this substantially copied from an existing file, or should it just
be 2016? (Not that it really matters, as I don't think we should have
copyright notices on tests like this at all, but that's something to
worry about another time.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 2151 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20161222/5b7bf915/attachment.bin>


More information about the Libstdc++ mailing list