diff options
| author | Howard Hinnant <hhinnant@apple.com> | 2013-08-07 23:02:42 +0000 |
|---|---|---|
| committer | Howard Hinnant <hhinnant@apple.com> | 2013-08-07 23:02:42 +0000 |
| commit | 9027f5e3deb9028f085f207b5dac39ff63f4285e (patch) | |
| tree | 715461280679568ff01c265e91a82077f9d9a2a3 /libcxx/include/__functional_base | |
| parent | 171817ee8ae888d595734a1b911d77dfa235ec9e (diff) | |
| download | bcm5719-llvm-9027f5e3deb9028f085f207b5dac39ff63f4285e.tar.gz bcm5719-llvm-9027f5e3deb9028f085f207b5dac39ff63f4285e.zip | |
Zhihao Yuan: Replace operator& with addressof in reference_wrapper constructor.
llvm-svn: 187927
Diffstat (limited to 'libcxx/include/__functional_base')
| -rw-r--r-- | libcxx/include/__functional_base | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/libcxx/include/__functional_base b/libcxx/include/__functional_base index 2bc2d2c1466..800b4b929c7 100644 --- a/libcxx/include/__functional_base +++ b/libcxx/include/__functional_base @@ -365,6 +365,56 @@ struct __invoke_return typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type; }; +// addressof + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +addressof(_Tp& __x) _NOEXCEPT +{ + return (_Tp*)&reinterpret_cast<const volatile char&>(__x); +} + +#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF) +// Objective-C++ Automatic Reference Counting uses qualified pointers +// that require special addressof() signatures. When +// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler +// itself is providing these definitions. Otherwise, we provide them. +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__strong _Tp* +addressof(__strong _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__weak _Tp* +addressof(__weak _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__autoreleasing _Tp* +addressof(__autoreleasing _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +template <class _Tp> +inline _LIBCPP_INLINE_VISIBILITY +__unsafe_unretained _Tp* +addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + template <class _Tp> class _LIBCPP_TYPE_VIS reference_wrapper : public __weak_result_type<_Tp> @@ -377,7 +427,8 @@ private: public: // construct/copy/destroy - _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT : __f_(&__f) {} + _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT + : __f_(_VSTD::addressof(__f)) {} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES private: reference_wrapper(type&&); public: // = delete; // do not bind to temps #endif |

