Index: include/memory =================================================================== --- include/memory +++ include/memory @@ -3711,6 +3711,18 @@ template class _LIBCPP_TEMPLATE_VIS enable_shared_from_this; +template +struct __ref_not_void +{ typedef _Tp& type; }; + +template<> +struct __ref_not_void +{ typedef void type; }; + +template +struct __compatible_with + : is_convertible*, remove_extent_t<_Up>*> {}; + template class _LIBCPP_TEMPLATE_VIS shared_ptr { @@ -3722,9 +3734,10 @@ public: #if _LIBCPP_STD_VER > 14 typedef weak_ptr<_Tp> weak_type; -#endif - + typedef remove_extent_t<_Tp> element_type; +#else typedef _Tp element_type; +#endif _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT; @@ -3732,13 +3745,13 @@ _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT; template explicit shared_ptr(_Yp* __p, - typename enable_if::value, __nat>::type = __nat()); + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()); template shared_ptr(_Yp* __p, _Dp __d, - typename enable_if::value, __nat>::type = __nat()); + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()); template shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, - typename enable_if::value, __nat>::type = __nat()); + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()); template shared_ptr(nullptr_t __p, _Dp __d); template shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a); template _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT; @@ -3747,13 +3760,13 @@ template _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, - typename enable_if::value, __nat>::type = __nat()) + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()) _NOEXCEPT; #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr&& __r) _NOEXCEPT; template _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r, - typename enable_if::value, __nat>::type = __nat()) + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()) _NOEXCEPT; #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES template explicit shared_ptr(const weak_ptr<_Yp>& __r, @@ -3762,11 +3775,11 @@ #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template shared_ptr(auto_ptr<_Yp>&& __r, - typename enable_if::value, __nat>::type = __nat()); + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()); #else template shared_ptr(auto_ptr<_Yp> __r, - typename enable_if::value, __nat>::type = __nat()); + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type = __nat()); #endif #endif template @@ -3795,7 +3808,7 @@ template typename enable_if < - is_convertible<_Yp*, element_type*>::value, + __compatible_with<_Yp, element_type>::value, shared_ptr& >::type _LIBCPP_INLINE_VISIBILITY @@ -3806,8 +3819,8 @@ template typename enable_if < - is_convertible<_Yp*, element_type*>::value, - shared_ptr<_Tp>& + __compatible_with<_Yp, element_type>::value, + shared_ptr& >::type _LIBCPP_INLINE_VISIBILITY operator=(shared_ptr<_Yp>&& __r); @@ -3857,7 +3870,7 @@ template typename enable_if < - is_convertible<_Yp*, element_type*>::value, + __compatible_with<_Yp, element_type>::value, void >::type _LIBCPP_INLINE_VISIBILITY @@ -3865,7 +3878,7 @@ template typename enable_if < - is_convertible<_Yp*, element_type*>::value, + __compatible_with<_Yp, element_type>::value, void >::type _LIBCPP_INLINE_VISIBILITY @@ -3873,7 +3886,7 @@ template typename enable_if < - is_convertible<_Yp*, element_type*>::value, + __compatible_with<_Yp, element_type>::value, void >::type _LIBCPP_INLINE_VISIBILITY @@ -3905,6 +3918,13 @@ __owner_equivalent(const shared_ptr& __p) const {return __cntrl_ == __p.__cntrl_;} +#if _LIBCPP_STD_VER > 14 + typename __ref_not_void<_Tp>::type + _LIBCPP_INLINE_VISIBILITY + operator[](ptrdiff_t __i) const + {return get()[__i];} // assert(get() != 0 && __i >= 0); +#endif + #ifndef _LIBCPP_NO_RTTI template _LIBCPP_INLINE_VISIBILITY @@ -4024,7 +4044,7 @@ template template shared_ptr<_Tp>::shared_ptr(_Yp* __p, - typename enable_if::value, __nat>::type) + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) : __ptr_(__p), __cntrl_(__allocate_shared(__p)) { @@ -4034,7 +4054,7 @@ template template shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, - typename enable_if::value, __nat>::type) + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) : __ptr_(__p), __cntrl_(__allocate_shared(__p, __d)) { @@ -4050,7 +4070,7 @@ template template shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a, - typename enable_if::value, __nat>::type) + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) : __ptr_(__p), __cntrl_(__allocate_shared(__p, __d, __a)) { @@ -4088,7 +4108,7 @@ template inline shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, - typename enable_if::value, __nat>::type) + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) @@ -4113,7 +4133,7 @@ template inline shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r, - typename enable_if::value, __nat>::type) + typename enable_if<__compatible_with<_Yp, element_type>::value, __nat>::type) _NOEXCEPT : __ptr_(__r.__ptr_), __cntrl_(__r.__cntrl_) @@ -4261,7 +4281,7 @@ inline typename enable_if < - is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, shared_ptr<_Tp>& >::type shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT @@ -4286,7 +4306,7 @@ inline typename enable_if < - is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, shared_ptr<_Tp>& >::type shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r) @@ -4387,7 +4407,7 @@ inline typename enable_if < - is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, void >::type shared_ptr<_Tp>::reset(_Yp* __p) @@ -4400,7 +4420,7 @@ inline typename enable_if < - is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, void >::type shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d) @@ -4413,7 +4433,7 @@ inline typename enable_if < - is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value, + __compatible_with<_Yp, typename shared_ptr<_Tp>::element_type>::value, void >::type shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a) @@ -4675,41 +4695,36 @@ template inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_array<_Tp>::value && !is_array<_Up>::value, - shared_ptr<_Tp> ->::type +shared_ptr<_Tp> static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT { - return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); + return shared_ptr<_Tp>(__r, static_cast*>(__r.get())); } template inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_array<_Tp>::value && !is_array<_Up>::value, - shared_ptr<_Tp> ->::type +shared_ptr<_Tp> dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT { - _Tp* __p = dynamic_cast<_Tp*>(__r.get()); + _Tp* __p = dynamic_cast*>(__r.get()); return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>(); } template -typename enable_if -< - is_array<_Tp>::value == is_array<_Up>::value, - shared_ptr<_Tp> ->::type +shared_ptr<_Tp> const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT { typedef typename remove_extent<_Tp>::type _RTp; return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get())); } +template +shared_ptr<_Tp> +reinterpret_pointer_cast(const shared_ptr<_Up>& __r) noexcept +{ + return shared_ptr<_Tp>(__r, reinterpret_cast*>(__r.get())); +} + #ifndef _LIBCPP_NO_RTTI template @@ -5108,7 +5123,7 @@ _LIBCPP_INLINE_VISIBILITY result_type operator()(const argument_type& __ptr) const _NOEXCEPT { - return hash<_Tp*>()(__ptr.get()); + return hash*>()(__ptr.get()); } }; Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp @@ -54,5 +54,5 @@ assert(!pB.owner_before(pA) && !pA.owner_before(pB)); } - return 0; + return 0; } Index: www/cxx1z_status.html =================================================================== --- www/cxx1z_status.html +++ www/cxx1z_status.html @@ -128,7 +128,7 @@ P0003R5LWGRemoving Deprecated Exception Specifications from C++17IssaquahComplete5.0 P0067R5LWGElementary string conversions, revision 5IssaquahPartially done P0403R1LWGLiteral suffixes for basic_string_viewIssaquahComplete4.0 - P0414R2LWGMerging shared_ptr changes from Library Fundamentals to C++17Issaquah + P0414R2LWGMerging shared_ptr changes from Library Fundamentals to C++17IssaquahComplete P0418R2LWGFail or succeed: there is no atomic latticeIssaquah P0426R1LWGConstexpr for std::char_traitsIssaquahComplete4.0 P0435R1LWGResolving LWG Issues re common_typeIssaquahComplete4.0