Path: blob/main/contrib/llvm-project/libcxx/include/__memory/auto_ptr.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_AUTO_PTR_H10#define _LIBCPP___MEMORY_AUTO_PTR_H1112#include <__config>1314#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)15# pragma GCC system_header16#endif1718#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)1920_LIBCPP_BEGIN_NAMESPACE_STD2122template <class _Tp>23struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref {24_Tp* __ptr_;25};2627template <class _Tp>28class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr {29private:30_Tp* __ptr_;3132public:33typedef _Tp element_type;3435_LIBCPP_HIDE_FROM_ABI explicit auto_ptr(_Tp* __p = 0) _NOEXCEPT : __ptr_(__p) {}36_LIBCPP_HIDE_FROM_ABI auto_ptr(auto_ptr& __p) _NOEXCEPT : __ptr_(__p.release()) {}37template <class _Up>38_LIBCPP_HIDE_FROM_ABI auto_ptr(auto_ptr<_Up>& __p) _NOEXCEPT : __ptr_(__p.release()) {}39_LIBCPP_HIDE_FROM_ABI auto_ptr& operator=(auto_ptr& __p) _NOEXCEPT {40reset(__p.release());41return *this;42}43template <class _Up>44_LIBCPP_HIDE_FROM_ABI auto_ptr& operator=(auto_ptr<_Up>& __p) _NOEXCEPT {45reset(__p.release());46return *this;47}48_LIBCPP_HIDE_FROM_ABI auto_ptr& operator=(auto_ptr_ref<_Tp> __p) _NOEXCEPT {49reset(__p.__ptr_);50return *this;51}52_LIBCPP_HIDE_FROM_ABI ~auto_ptr() _NOEXCEPT { delete __ptr_; }5354_LIBCPP_HIDE_FROM_ABI _Tp& operator*() const _NOEXCEPT { return *__ptr_; }55_LIBCPP_HIDE_FROM_ABI _Tp* operator->() const _NOEXCEPT { return __ptr_; }56_LIBCPP_HIDE_FROM_ABI _Tp* get() const _NOEXCEPT { return __ptr_; }57_LIBCPP_HIDE_FROM_ABI _Tp* release() _NOEXCEPT {58_Tp* __t = __ptr_;59__ptr_ = nullptr;60return __t;61}62_LIBCPP_HIDE_FROM_ABI void reset(_Tp* __p = 0) _NOEXCEPT {63if (__ptr_ != __p)64delete __ptr_;65__ptr_ = __p;66}6768_LIBCPP_HIDE_FROM_ABI auto_ptr(auto_ptr_ref<_Tp> __p) _NOEXCEPT : __ptr_(__p.__ptr_) {}69template <class _Up>70_LIBCPP_HIDE_FROM_ABI operator auto_ptr_ref<_Up>() _NOEXCEPT {71auto_ptr_ref<_Up> __t;72__t.__ptr_ = release();73return __t;74}75template <class _Up>76_LIBCPP_HIDE_FROM_ABI operator auto_ptr<_Up>() _NOEXCEPT {77return auto_ptr<_Up>(release());78}79};8081template <>82class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void> {83public:84typedef void element_type;85};8687_LIBCPP_END_NAMESPACE_STD8889#endif // _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)9091#endif // _LIBCPP___MEMORY_AUTO_PTR_H929394