Define std::owner_less<void> specialization (P0074R0)
authorJonathan Wakely <jwakely@redhat.com>
Wed, 3 Aug 2016 18:11:18 +0000 (19:11 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 3 Aug 2016 18:11:18 +0000 (19:11 +0100)
* include/bits/shared_ptr.h (owner_less): Add default template
argument.
* include/bits/shared_ptr_base.h (_Sp_owner_less<void, void>): Define
specialization.
(owner_less<void>): Define specialization.
* include/bits/stl_function.h (__cpp_lib_transparent_operators):
Update value.
* testsuite/20_util/owner_less/void.cc: New test.
* testsuite/experimental/feat-cxx14.cc: Update macro value tested.

From-SVN: r239089

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/shared_ptr.h
libstdc++-v3/include/bits/shared_ptr_base.h
libstdc++-v3/include/bits/stl_function.h
libstdc++-v3/testsuite/20_util/owner_less/void.cc [new file with mode: 0644]
libstdc++-v3/testsuite/experimental/feat-cxx14.cc

index 61135055e37fa6dc2ac309a3e80f8b6e4bf62b5a..8bc5b2e7176bc0ea249161f3924cf3ef2e3c557e 100644 (file)
@@ -1,5 +1,15 @@
 2016-08-03  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/bits/shared_ptr.h (owner_less): Add default template
+       argument.
+       * include/bits/shared_ptr_base.h (_Sp_owner_less<void, void>): Define
+       specialization.
+       (owner_less<void>): Define specialization.
+       * include/bits/stl_function.h (__cpp_lib_transparent_operators):
+       Update value.
+       * testsuite/20_util/owner_less/void.cc: New test.
+       * testsuite/experimental/feat-cxx14.cc: Update macro value tested.
+
        * include/bits/allocator.h (__cpp_lib_incomplete_container_elements):
        Define feature-test macro.
        * include/bits/range_access.h (__cpp_lib_array_constexpr): Likewise.
index b22477e96b29acefa3f8c93b7be15945d83e6133..16f78f7968a8e8e5a668c5829982b13fd767e51a 100644 (file)
@@ -535,9 +535,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 
   /// Primary template owner_less
-  template<typename _Tp>
+  template<typename _Tp = void>
     struct owner_less;
 
+  /// Void specialization of owner_less
+  template<>
+    struct owner_less<void> : _Sp_owner_less<void, void>
+    { };
+
   /// Partial specialization of owner_less for shared_ptr.
   template<typename _Tp>
     struct owner_less<shared_ptr<_Tp>>
index e844c9c91fe5cedf219afabd91836727f82c9af6..1474df603b7f96dbd9fc5cceb3385524ca9fc928 100644 (file)
@@ -1506,6 +1506,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return __lhs.owner_before(__rhs); }
     };
 
+  template<>
+    struct _Sp_owner_less<void, void>
+    {
+      template<typename _Tp, typename _Up>
+       auto
+       operator()(const _Tp& __lhs, const _Up& __rhs) const
+       -> decltype(__lhs.owner_before(__rhs))
+       { return __lhs.owner_before(__rhs); }
+
+      using is_transparent = void;
+    };
+
   template<typename _Tp, _Lock_policy _Lp>
     struct owner_less<__shared_ptr<_Tp, _Lp>>
     : public _Sp_owner_less<__shared_ptr<_Tp, _Lp>, __weak_ptr<_Tp, _Lp>>
index 68f39ff2690b7e0a3e416d87f4283e261e2b6c95..1408da6e37e16af60edd24a90ce9cfd69ea52383 100644 (file)
@@ -224,7 +224,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cplusplus > 201103L
 
-#define __cpp_lib_transparent_operators 201210
+#define __cpp_lib_transparent_operators 201510
 
   template<>
     struct plus<void>
diff --git a/libstdc++-v3/testsuite/20_util/owner_less/void.cc b/libstdc++-v3/testsuite/20_util/owner_less/void.cc
new file mode 100644 (file)
index 0000000..4facbf5
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (C) 2016 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do compile { target c++11 } }
+
+#include <memory>
+
+#if __cplusplus >= 201402L
+// The feature-test macro is only defined for C++14 and later.
+# if __cpp_lib_transparent_operators < 201510
+#  error "__cpp_lib_transparent_operators < 201510"
+# endif
+#endif
+
+void
+test01()
+{
+  using namespace std;
+
+  static_assert(is_same<owner_less<>, owner_less<void>>::value,
+                "owner_less<> uses void specialization");
+
+  shared_ptr<int> sp1;
+  shared_ptr<void> sp2;
+  shared_ptr<long> sp3;
+  weak_ptr<int> wp1;
+
+  owner_less<> cmp;
+  cmp(sp1, sp2);
+  cmp(sp1, wp1);
+  cmp(sp1, sp3);
+  cmp(wp1, sp1);
+  cmp(wp1, wp1);
+}
index 42b633f6ef6d6af47bb355400298e7330745ff28..c61f7b00f68757775be14923ce234775b7ec6fb6 100644 (file)
@@ -40,8 +40,8 @@
 
 #ifndef  __cpp_lib_transparent_operators
 #  error "__cpp_lib_transparent_operators"
-#elif  __cpp_lib_transparent_operators != 201210
-#  error "__cpp_lib_transparent_operators != 201210"
+#elif  __cpp_lib_transparent_operators < 201210
+#  error "__cpp_lib_transparent_operators < 201210"
 #endif
 
 #ifndef  __cpp_lib_result_of_sfinae