Path: blob/main/contrib/llvm-project/libcxx/include/__memory/addressof.h
35233 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___MEMORY_ADDRESSOF_H10#define _LIBCPP___MEMORY_ADDRESSOF_H1112#include <__config>1314#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)15# pragma GCC system_header16#endif1718_LIBCPP_BEGIN_NAMESPACE_STD1920template <class _Tp>21inline _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_NO_CFI _LIBCPP_HIDE_FROM_ABI _Tp* addressof(_Tp& __x) _NOEXCEPT {22return __builtin_addressof(__x);23}2425#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)26// Objective-C++ Automatic Reference Counting uses qualified pointers27// that require special addressof() signatures. When28// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler29// itself is providing these definitions. Otherwise, we provide them.30template <class _Tp>31inline _LIBCPP_HIDE_FROM_ABI __strong _Tp* addressof(__strong _Tp& __x) _NOEXCEPT {32return &__x;33}3435# ifdef _LIBCPP_HAS_OBJC_ARC_WEAK36template <class _Tp>37inline _LIBCPP_HIDE_FROM_ABI __weak _Tp* addressof(__weak _Tp& __x) _NOEXCEPT {38return &__x;39}40# endif4142template <class _Tp>43inline _LIBCPP_HIDE_FROM_ABI __autoreleasing _Tp* addressof(__autoreleasing _Tp& __x) _NOEXCEPT {44return &__x;45}4647template <class _Tp>48inline _LIBCPP_HIDE_FROM_ABI __unsafe_unretained _Tp* addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT {49return &__x;50}51#endif5253#if !defined(_LIBCPP_CXX03_LANG)54template <class _Tp>55_Tp* addressof(const _Tp&&) noexcept = delete;56#endif5758_LIBCPP_END_NAMESPACE_STD5960#endif // _LIBCPP___MEMORY_ADDRESSOF_H616263