mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-23 10:07:41 +08:00
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. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@273839 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -756,7 +756,7 @@ template <unsigned> struct __static_assert_check {};
|
|||||||
# elif __cplusplus <= 201402L
|
# elif __cplusplus <= 201402L
|
||||||
# define _LIBCPP_STD_VER 14
|
# define _LIBCPP_STD_VER 14
|
||||||
# else
|
# 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
|
||||||
#endif // _LIBCPP_STD_VER
|
#endif // _LIBCPP_STD_VER
|
||||||
|
|
||||||
|
@@ -361,6 +361,7 @@ class shared_ptr
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef T element_type;
|
typedef T element_type;
|
||||||
|
typedef weak_ptr<T> weak_type; // C++17
|
||||||
|
|
||||||
// constructors:
|
// constructors:
|
||||||
constexpr shared_ptr() noexcept;
|
constexpr shared_ptr() noexcept;
|
||||||
@@ -3863,6 +3864,9 @@ class _LIBCPP_TYPE_VIS_ONLY shared_ptr
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef _Tp element_type;
|
typedef _Tp element_type;
|
||||||
|
#if _LIBCPP_STD_VER > 14
|
||||||
|
typedef weak_ptr<_Tp> weak_type;
|
||||||
|
#endif
|
||||||
private:
|
private:
|
||||||
element_type* __ptr_;
|
element_type* __ptr_;
|
||||||
__shared_weak_count* __cntrl_;
|
__shared_weak_count* __cntrl_;
|
||||||
|
@@ -13,14 +13,20 @@
|
|||||||
// {
|
// {
|
||||||
// public:
|
// public:
|
||||||
// typedef T element_type;
|
// typedef T element_type;
|
||||||
|
// typedef weak_ptr<T> weak_type; // C++17
|
||||||
// ...
|
// ...
|
||||||
// };
|
// };
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "test_macros.h"
|
||||||
|
|
||||||
struct A; // purposefully incomplete
|
struct A; // purposefully incomplete
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
static_assert((std::is_same<std::shared_ptr<A>::element_type, A>::value), "");
|
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
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,7 @@
|
|||||||
#elif __cplusplus <= 201402L
|
#elif __cplusplus <= 201402L
|
||||||
# define TEST_STD_VER 14
|
# define TEST_STD_VER 14
|
||||||
#else
|
#else
|
||||||
# define TEST_STD_VER 99 // greater than current standard
|
# define TEST_STD_VER 16 // current year; greater than current standard
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user