[libcxx] r273839 - Implement P0163r0. Add shared_ptr::weak_type.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 26 18:02:43 PDT 2016


Author: ericwf
Date: Sun Jun 26 20:02:43 2016
New Revision: 273839

URL: http://llvm.org/viewvc/llvm-project?rev=273839&view=rev
Log:
Implement P0163r0. Add shared_ptr::weak_type.

This patch adds the weak_type typedef in shared_ptr. It is available in
C++17 and newer.

This patch also updates the _LIBCPP_STD_VER and TEST_STD_VER macros to
have the value of 16, since 2016 is the current year.

Modified:
    libcxx/trunk/include/__config
    libcxx/trunk/include/memory
    libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp
    libcxx/trunk/test/support/test_macros.h

Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=273839&r1=273838&r2=273839&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Sun Jun 26 20:02:43 2016
@@ -756,7 +756,7 @@ template <unsigned> struct __static_asse
 #  elif __cplusplus <= 201402L
 #    define _LIBCPP_STD_VER 14
 #  else
-#    define _LIBCPP_STD_VER 15  // current year, or date of c++17 ratification
+#    define _LIBCPP_STD_VER 16  // current year, or date of c++17 ratification
 #  endif
 #endif  // _LIBCPP_STD_VER
 

Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=273839&r1=273838&r2=273839&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Sun Jun 26 20:02:43 2016
@@ -361,6 +361,7 @@ class shared_ptr
 {
 public:
     typedef T element_type;
+    typedef weak_ptr<T> weak_type; // C++17
 
     // constructors:
     constexpr shared_ptr() noexcept;
@@ -3863,6 +3864,9 @@ class _LIBCPP_TYPE_VIS_ONLY shared_ptr
 {
 public:
     typedef _Tp element_type;
+#if _LIBCPP_STD_VER > 14
+    typedef weak_ptr<_Tp> weak_type;
+#endif
 private:
     element_type*      __ptr_;
     __shared_weak_count* __cntrl_;

Modified: libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp?rev=273839&r1=273838&r2=273839&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp Sun Jun 26 20:02:43 2016
@@ -13,14 +13,20 @@
 // {
 // public:
 //     typedef T element_type;
+//     typedef weak_ptr<T> weak_type; // C++17
 //     ...
 // };
 
 #include <memory>
 
+#include "test_macros.h"
+
 struct A;  // purposefully incomplete
 
 int main()
 {
     static_assert((std::is_same<std::shared_ptr<A>::element_type, A>::value), "");
+#if TEST_STD_VER > 14
+    static_assert((std::is_same<std::shared_ptr<A>::weak_type, std::weak_ptr<A>>::value), "");
+#endif
 }

Modified: libcxx/trunk/test/support/test_macros.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_macros.h?rev=273839&r1=273838&r2=273839&view=diff
==============================================================================
--- libcxx/trunk/test/support/test_macros.h (original)
+++ libcxx/trunk/test/support/test_macros.h Sun Jun 26 20:02:43 2016
@@ -43,7 +43,7 @@
 #elif __cplusplus <= 201402L
 # define TEST_STD_VER 14
 #else
-# define TEST_STD_VER 99    // greater than current standard
+# define TEST_STD_VER 16    // current year; greater than current standard
 #endif
 #endif
 




More information about the cfe-commits mailing list