| File: | src/gnu/usr.bin/clang/liblldbPluginSymbolFile/../../../llvm/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp |
| Warning: | line 146, column 29 Method called on moved-from object 'debug_stream' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | //===-- CompileUnitIndex.cpp ----------------------------------------------===// | |||
| 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-exception | |||
| 6 | // | |||
| 7 | //===----------------------------------------------------------------------===// | |||
| 8 | ||||
| 9 | #include "CompileUnitIndex.h" | |||
| 10 | ||||
| 11 | #include "PdbIndex.h" | |||
| 12 | #include "PdbUtil.h" | |||
| 13 | ||||
| 14 | #include "llvm/DebugInfo/CodeView/LazyRandomTypeCollection.h" | |||
| 15 | #include "llvm/DebugInfo/CodeView/SymbolDeserializer.h" | |||
| 16 | #include "llvm/DebugInfo/CodeView/TypeDeserializer.h" | |||
| 17 | #include "llvm/DebugInfo/MSF/MappedBlockStream.h" | |||
| 18 | #include "llvm/DebugInfo/PDB/Native/DbiModuleDescriptor.h" | |||
| 19 | #include "llvm/DebugInfo/PDB/Native/DbiStream.h" | |||
| 20 | #include "llvm/DebugInfo/PDB/Native/InfoStream.h" | |||
| 21 | #include "llvm/DebugInfo/PDB/Native/ModuleDebugStream.h" | |||
| 22 | #include "llvm/DebugInfo/PDB/Native/NamedStreamMap.h" | |||
| 23 | #include "llvm/DebugInfo/PDB/Native/TpiStream.h" | |||
| 24 | #include "llvm/Support/Path.h" | |||
| 25 | ||||
| 26 | #include "lldb/Utility/LLDBAssert.h" | |||
| 27 | ||||
| 28 | using namespace lldb; | |||
| 29 | using namespace lldb_private; | |||
| 30 | using namespace lldb_private::npdb; | |||
| 31 | using namespace llvm::codeview; | |||
| 32 | using namespace llvm::pdb; | |||
| 33 | ||||
| 34 | static bool IsMainFile(llvm::StringRef main, llvm::StringRef other) { | |||
| 35 | if (main == other) | |||
| 36 | return true; | |||
| 37 | ||||
| 38 | // If the files refer to the local file system, we can just ask the file | |||
| 39 | // system if they're equivalent. But if the source isn't present on disk | |||
| 40 | // then we still want to try. | |||
| 41 | if (llvm::sys::fs::equivalent(main, other)) | |||
| 42 | return true; | |||
| 43 | ||||
| 44 | llvm::SmallString<64> normalized(other); | |||
| 45 | llvm::sys::path::native(normalized); | |||
| 46 | return main.equals_insensitive(normalized); | |||
| 47 | } | |||
| 48 | ||||
| 49 | static void ParseCompile3(const CVSymbol &sym, CompilandIndexItem &cci) { | |||
| 50 | cci.m_compile_opts.emplace(); | |||
| 51 | llvm::cantFail( | |||
| 52 | SymbolDeserializer::deserializeAs<Compile3Sym>(sym, *cci.m_compile_opts)); | |||
| 53 | } | |||
| 54 | ||||
| 55 | static void ParseObjname(const CVSymbol &sym, CompilandIndexItem &cci) { | |||
| 56 | cci.m_obj_name.emplace(); | |||
| 57 | llvm::cantFail( | |||
| 58 | SymbolDeserializer::deserializeAs<ObjNameSym>(sym, *cci.m_obj_name)); | |||
| 59 | } | |||
| 60 | ||||
| 61 | static void ParseBuildInfo(PdbIndex &index, const CVSymbol &sym, | |||
| 62 | CompilandIndexItem &cci) { | |||
| 63 | BuildInfoSym bis(SymbolRecordKind::BuildInfoSym); | |||
| 64 | llvm::cantFail(SymbolDeserializer::deserializeAs<BuildInfoSym>(sym, bis)); | |||
| 65 | ||||
| 66 | // S_BUILDINFO just points to an LF_BUILDINFO in the IPI stream. Let's do | |||
| 67 | // a little extra work to pull out the LF_BUILDINFO. | |||
| 68 | LazyRandomTypeCollection &types = index.ipi().typeCollection(); | |||
| 69 | llvm::Optional<CVType> cvt = types.tryGetType(bis.BuildId); | |||
| 70 | ||||
| 71 | if (!cvt || cvt->kind() != LF_BUILDINFO) | |||
| 72 | return; | |||
| 73 | ||||
| 74 | BuildInfoRecord bir; | |||
| 75 | llvm::cantFail(TypeDeserializer::deserializeAs<BuildInfoRecord>(*cvt, bir)); | |||
| 76 | cci.m_build_info.assign(bir.ArgIndices.begin(), bir.ArgIndices.end()); | |||
| 77 | } | |||
| 78 | ||||
| 79 | static void ParseExtendedInfo(PdbIndex &index, CompilandIndexItem &item) { | |||
| 80 | const CVSymbolArray &syms = item.m_debug_stream.getSymbolArray(); | |||
| 81 | ||||
| 82 | // This is a private function, it shouldn't be called if the information | |||
| 83 | // has already been parsed. | |||
| 84 | lldbassert(!item.m_obj_name)lldb_private::lldb_assert(static_cast<bool>(!item.m_obj_name ), "!item.m_obj_name", __FUNCTION__, "/usr/src/gnu/usr.bin/clang/liblldbPluginSymbolFile/../../../llvm/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp" , 84); | |||
| 85 | lldbassert(!item.m_compile_opts)lldb_private::lldb_assert(static_cast<bool>(!item.m_compile_opts ), "!item.m_compile_opts", __FUNCTION__, "/usr/src/gnu/usr.bin/clang/liblldbPluginSymbolFile/../../../llvm/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp" , 85); | |||
| 86 | lldbassert(item.m_build_info.empty())lldb_private::lldb_assert(static_cast<bool>(item.m_build_info .empty()), "item.m_build_info.empty()", __FUNCTION__, "/usr/src/gnu/usr.bin/clang/liblldbPluginSymbolFile/../../../llvm/lldb/source/Plugins/SymbolFile/NativePDB/CompileUnitIndex.cpp" , 86); | |||
| 87 | ||||
| 88 | // We're looking for 3 things. S_COMPILE3, S_OBJNAME, and S_BUILDINFO. | |||
| 89 | int found = 0; | |||
| 90 | for (const CVSymbol &sym : syms) { | |||
| 91 | switch (sym.kind()) { | |||
| 92 | case S_COMPILE3: | |||
| 93 | ParseCompile3(sym, item); | |||
| 94 | break; | |||
| 95 | case S_OBJNAME: | |||
| 96 | ParseObjname(sym, item); | |||
| 97 | break; | |||
| 98 | case S_BUILDINFO: | |||
| 99 | ParseBuildInfo(index, sym, item); | |||
| 100 | break; | |||
| 101 | default: | |||
| 102 | continue; | |||
| 103 | } | |||
| 104 | if (++found >= 3) | |||
| 105 | break; | |||
| 106 | } | |||
| 107 | } | |||
| 108 | ||||
| 109 | CompilandIndexItem::CompilandIndexItem( | |||
| 110 | PdbCompilandId id, llvm::pdb::ModuleDebugStreamRef debug_stream, | |||
| 111 | llvm::pdb::DbiModuleDescriptor descriptor) | |||
| 112 | : m_id(id), m_debug_stream(std::move(debug_stream)), | |||
| 113 | m_module_descriptor(std::move(descriptor)) {} | |||
| 114 | ||||
| 115 | CompilandIndexItem &CompileUnitIndex::GetOrCreateCompiland(uint16_t modi) { | |||
| 116 | auto result = m_comp_units.try_emplace(modi, nullptr); | |||
| 117 | if (!result.second) | |||
| ||||
| 118 | return *result.first->second; | |||
| 119 | ||||
| 120 | // Find the module list and load its debug information stream and cache it | |||
| 121 | // since we need to use it for almost all interesting operations. | |||
| 122 | const DbiModuleList &modules = m_index.dbi().modules(); | |||
| 123 | llvm::pdb::DbiModuleDescriptor descriptor = modules.getModuleDescriptor(modi); | |||
| 124 | uint16_t stream = descriptor.getModuleStreamIndex(); | |||
| 125 | std::unique_ptr<llvm::msf::MappedBlockStream> stream_data = | |||
| 126 | m_index.pdb().createIndexedStream(stream); | |||
| 127 | ||||
| 128 | ||||
| 129 | std::unique_ptr<CompilandIndexItem>& cci = result.first->second; | |||
| 130 | ||||
| 131 | if (!stream_data) { | |||
| 132 | llvm::pdb::ModuleDebugStreamRef debug_stream(descriptor, nullptr); | |||
| 133 | cci = std::make_unique<CompilandIndexItem>(PdbCompilandId{ modi }, debug_stream, std::move(descriptor)); | |||
| 134 | return *cci; | |||
| 135 | } | |||
| 136 | ||||
| 137 | llvm::pdb::ModuleDebugStreamRef debug_stream(descriptor, | |||
| 138 | std::move(stream_data)); | |||
| 139 | ||||
| 140 | cantFail(debug_stream.reload()); | |||
| 141 | ||||
| 142 | cci = std::make_unique<CompilandIndexItem>( | |||
| 143 | PdbCompilandId{modi}, std::move(debug_stream), std::move(descriptor)); | |||
| 144 | ParseExtendedInfo(m_index, *cci); | |||
| 145 | ||||
| 146 | cci->m_strings.initialize(debug_stream.getSubsectionsArray()); | |||
| ||||
| 147 | PDBStringTable &strings = cantFail(m_index.pdb().getStringTable()); | |||
| 148 | cci->m_strings.setStrings(strings.getStringTable()); | |||
| 149 | ||||
| 150 | // We want the main source file to always comes first. Note that we can't | |||
| 151 | // just push_back the main file onto the front because `GetMainSourceFile` | |||
| 152 | // computes it in such a way that it doesn't own the resulting memory. So we | |||
| 153 | // have to iterate the module file list comparing each one to the main file | |||
| 154 | // name until we find it, and we can cache that one since the memory is backed | |||
| 155 | // by a contiguous chunk inside the mapped PDB. | |||
| 156 | llvm::SmallString<64> main_file = GetMainSourceFile(*cci); | |||
| 157 | std::string s = std::string(main_file.str()); | |||
| 158 | llvm::sys::path::native(main_file); | |||
| 159 | ||||
| 160 | uint32_t file_count = modules.getSourceFileCount(modi); | |||
| 161 | cci->m_file_list.reserve(file_count); | |||
| 162 | bool found_main_file = false; | |||
| 163 | for (llvm::StringRef file : modules.source_files(modi)) { | |||
| 164 | if (!found_main_file && IsMainFile(main_file, file)) { | |||
| 165 | cci->m_file_list.insert(cci->m_file_list.begin(), file); | |||
| 166 | found_main_file = true; | |||
| 167 | continue; | |||
| 168 | } | |||
| 169 | cci->m_file_list.push_back(file); | |||
| 170 | } | |||
| 171 | ||||
| 172 | return *cci; | |||
| 173 | } | |||
| 174 | ||||
| 175 | const CompilandIndexItem *CompileUnitIndex::GetCompiland(uint16_t modi) const { | |||
| 176 | auto iter = m_comp_units.find(modi); | |||
| 177 | if (iter == m_comp_units.end()) | |||
| 178 | return nullptr; | |||
| 179 | return iter->second.get(); | |||
| 180 | } | |||
| 181 | ||||
| 182 | CompilandIndexItem *CompileUnitIndex::GetCompiland(uint16_t modi) { | |||
| 183 | auto iter = m_comp_units.find(modi); | |||
| 184 | if (iter == m_comp_units.end()) | |||
| 185 | return nullptr; | |||
| 186 | return iter->second.get(); | |||
| 187 | } | |||
| 188 | ||||
| 189 | llvm::SmallString<64> | |||
| 190 | CompileUnitIndex::GetMainSourceFile(const CompilandIndexItem &item) const { | |||
| 191 | // LF_BUILDINFO contains a list of arg indices which point to LF_STRING_ID | |||
| 192 | // records in the IPI stream. The order of the arg indices is as follows: | |||
| 193 | // [0] - working directory where compiler was invoked. | |||
| 194 | // [1] - absolute path to compiler binary | |||
| 195 | // [2] - source file name | |||
| 196 | // [3] - path to compiler generated PDB (the /Zi PDB, although this entry gets | |||
| 197 | // added even when using /Z7) | |||
| 198 | // [4] - full command line invocation. | |||
| 199 | // | |||
| 200 | // We need to form the path [0]\[2] to generate the full path to the main | |||
| 201 | // file.source | |||
| 202 | if (item.m_build_info.size() < 3) | |||
| 203 | return {""}; | |||
| 204 | ||||
| 205 | LazyRandomTypeCollection &types = m_index.ipi().typeCollection(); | |||
| 206 | ||||
| 207 | StringIdRecord working_dir; | |||
| 208 | StringIdRecord file_name; | |||
| 209 | CVType dir_cvt = types.getType(item.m_build_info[0]); | |||
| 210 | CVType file_cvt = types.getType(item.m_build_info[2]); | |||
| 211 | llvm::cantFail( | |||
| 212 | TypeDeserializer::deserializeAs<StringIdRecord>(dir_cvt, working_dir)); | |||
| 213 | llvm::cantFail( | |||
| 214 | TypeDeserializer::deserializeAs<StringIdRecord>(file_cvt, file_name)); | |||
| 215 | ||||
| 216 | llvm::sys::path::Style style = working_dir.String.startswith("/") | |||
| 217 | ? llvm::sys::path::Style::posix | |||
| 218 | : llvm::sys::path::Style::windows; | |||
| 219 | if (llvm::sys::path::is_absolute(file_name.String, style)) | |||
| 220 | return file_name.String; | |||
| 221 | ||||
| 222 | llvm::SmallString<64> absolute_path = working_dir.String; | |||
| 223 | llvm::sys::path::append(absolute_path, file_name.String); | |||
| 224 | return absolute_path; | |||
| 225 | } |
| 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___MEMORY_UNIQUE_PTR_H |
| 11 | #define _LIBCPP___MEMORY_UNIQUE_PTR_H |
| 12 | |
| 13 | #include <__config> |
| 14 | #include <__functional_base> |
| 15 | #include <__functional/hash.h> |
| 16 | #include <__functional/operations.h> |
| 17 | #include <__memory/allocator_traits.h> // __pointer |
| 18 | #include <__memory/compressed_pair.h> |
| 19 | #include <__utility/forward.h> |
| 20 | #include <cstddef> |
| 21 | #include <type_traits> |
| 22 | #include <utility> |
| 23 | |
| 24 | #if _LIBCPP_STD_VER14 <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
| 25 | # include <__memory/auto_ptr.h> |
| 26 | #endif |
| 27 | |
| 28 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 29 | #pragma GCC system_header |
| 30 | #endif |
| 31 | |
| 32 | _LIBCPP_PUSH_MACROSpush_macro("min") push_macro("max") |
| 33 | #include <__undef_macros> |
| 34 | |
| 35 | _LIBCPP_BEGIN_NAMESPACE_STDnamespace std { inline namespace __1 { |
| 36 | |
| 37 | template <class _Tp> |
| 38 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) default_delete { |
| 39 | static_assert(!is_function<_Tp>::value, |
| 40 | "default_delete cannot be instantiated for function types"); |
| 41 | #ifndef _LIBCPP_CXX03_LANG |
| 42 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) constexpr default_delete() _NOEXCEPTnoexcept = default; |
| 43 | #else |
| 44 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) default_delete() {} |
| 45 | #endif |
| 46 | template <class _Up> |
| 47 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 48 | default_delete(const default_delete<_Up>&, |
| 49 | typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = |
| 50 | 0) _NOEXCEPTnoexcept {} |
| 51 | |
| 52 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) void operator()(_Tp* __ptr) const _NOEXCEPTnoexcept { |
| 53 | static_assert(sizeof(_Tp) > 0, |
| 54 | "default_delete can not delete incomplete type"); |
| 55 | static_assert(!is_void<_Tp>::value, |
| 56 | "default_delete can not delete incomplete type"); |
| 57 | delete __ptr; |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | template <class _Tp> |
| 62 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) default_delete<_Tp[]> { |
| 63 | private: |
| 64 | template <class _Up> |
| 65 | struct _EnableIfConvertible |
| 66 | : enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {}; |
| 67 | |
| 68 | public: |
| 69 | #ifndef _LIBCPP_CXX03_LANG |
| 70 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) constexpr default_delete() _NOEXCEPTnoexcept = default; |
| 71 | #else |
| 72 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) default_delete() {} |
| 73 | #endif |
| 74 | |
| 75 | template <class _Up> |
| 76 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 77 | default_delete(const default_delete<_Up[]>&, |
| 78 | typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPTnoexcept {} |
| 79 | |
| 80 | template <class _Up> |
| 81 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 82 | typename _EnableIfConvertible<_Up>::type |
| 83 | operator()(_Up* __ptr) const _NOEXCEPTnoexcept { |
| 84 | static_assert(sizeof(_Tp) > 0, |
| 85 | "default_delete can not delete incomplete type"); |
| 86 | static_assert(!is_void<_Tp>::value, |
| 87 | "default_delete can not delete void type"); |
| 88 | delete[] __ptr; |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | template <class _Deleter> |
| 93 | struct __unique_ptr_deleter_sfinae { |
| 94 | static_assert(!is_reference<_Deleter>::value, "incorrect specialization"); |
| 95 | typedef const _Deleter& __lval_ref_type; |
| 96 | typedef _Deleter&& __good_rval_ref_type; |
| 97 | typedef true_type __enable_rval_overload; |
| 98 | }; |
| 99 | |
| 100 | template <class _Deleter> |
| 101 | struct __unique_ptr_deleter_sfinae<_Deleter const&> { |
| 102 | typedef const _Deleter& __lval_ref_type; |
| 103 | typedef const _Deleter&& __bad_rval_ref_type; |
| 104 | typedef false_type __enable_rval_overload; |
| 105 | }; |
| 106 | |
| 107 | template <class _Deleter> |
| 108 | struct __unique_ptr_deleter_sfinae<_Deleter&> { |
| 109 | typedef _Deleter& __lval_ref_type; |
| 110 | typedef _Deleter&& __bad_rval_ref_type; |
| 111 | typedef false_type __enable_rval_overload; |
| 112 | }; |
| 113 | |
| 114 | #if defined(_LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI) |
| 115 | # define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI __attribute__((trivial_abi)) |
| 116 | #else |
| 117 | # define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI |
| 118 | #endif |
| 119 | |
| 120 | template <class _Tp, class _Dp = default_delete<_Tp> > |
| 121 | class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) unique_ptr { |
| 122 | public: |
| 123 | typedef _Tp element_type; |
| 124 | typedef _Dp deleter_type; |
| 125 | typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) typename __pointer<_Tp, deleter_type>::type pointer; |
| 126 | |
| 127 | static_assert(!is_rvalue_reference<deleter_type>::value, |
| 128 | "the specified deleter type cannot be an rvalue reference"); |
| 129 | |
| 130 | private: |
| 131 | __compressed_pair<pointer, deleter_type> __ptr_; |
| 132 | |
| 133 | struct __nat { int __for_bool_; }; |
| 134 | |
| 135 | typedef _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; |
| 136 | |
| 137 | template <bool _Dummy> |
| 138 | using _LValRefType _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = |
| 139 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; |
| 140 | |
| 141 | template <bool _Dummy> |
| 142 | using _GoodRValRefType _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = |
| 143 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; |
| 144 | |
| 145 | template <bool _Dummy> |
| 146 | using _BadRValRefType _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = |
| 147 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; |
| 148 | |
| 149 | template <bool _Dummy, class _Deleter = typename __dependent_type< |
| 150 | __identity<deleter_type>, _Dummy>::type> |
| 151 | using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = |
| 152 | typename enable_if<is_default_constructible<_Deleter>::value && |
| 153 | !is_pointer<_Deleter>::value>::type; |
| 154 | |
| 155 | template <class _ArgType> |
| 156 | using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = |
| 157 | typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; |
| 158 | |
| 159 | template <class _UPtr, class _Up> |
| 160 | using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename enable_if< |
| 161 | is_convertible<typename _UPtr::pointer, pointer>::value && |
| 162 | !is_array<_Up>::value |
| 163 | >::type; |
| 164 | |
| 165 | template <class _UDel> |
| 166 | using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename enable_if< |
| 167 | (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || |
| 168 | (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) |
| 169 | >::type; |
| 170 | |
| 171 | template <class _UDel> |
| 172 | using _EnableIfDeleterAssignable = typename enable_if< |
| 173 | is_assignable<_Dp&, _UDel&&>::value |
| 174 | >::type; |
| 175 | |
| 176 | public: |
| 177 | template <bool _Dummy = true, |
| 178 | class = _EnableIfDeleterDefaultConstructible<_Dummy> > |
| 179 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 180 | _LIBCPP_CONSTEXPRconstexpr unique_ptr() _NOEXCEPTnoexcept : __ptr_(pointer(), __default_init_tag()) {} |
| 181 | |
| 182 | template <bool _Dummy = true, |
| 183 | class = _EnableIfDeleterDefaultConstructible<_Dummy> > |
| 184 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 185 | _LIBCPP_CONSTEXPRconstexpr unique_ptr(nullptr_t) _NOEXCEPTnoexcept : __ptr_(pointer(), __default_init_tag()) {} |
| 186 | |
| 187 | template <bool _Dummy = true, |
| 188 | class = _EnableIfDeleterDefaultConstructible<_Dummy> > |
| 189 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 190 | explicit unique_ptr(pointer __p) _NOEXCEPTnoexcept : __ptr_(__p, __default_init_tag()) {} |
| 191 | |
| 192 | template <bool _Dummy = true, |
| 193 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > |
| 194 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 195 | unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPTnoexcept |
| 196 | : __ptr_(__p, __d) {} |
| 197 | |
| 198 | template <bool _Dummy = true, |
| 199 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > |
| 200 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 201 | unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPTnoexcept |
| 202 | : __ptr_(__p, _VSTDstd::__1::move(__d)) { |
| 203 | static_assert(!is_reference<deleter_type>::value, |
| 204 | "rvalue deleter bound to reference"); |
| 205 | } |
| 206 | |
| 207 | template <bool _Dummy = true, |
| 208 | class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > > |
| 209 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 210 | unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete; |
| 211 | |
| 212 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 213 | unique_ptr(unique_ptr&& __u) _NOEXCEPTnoexcept |
| 214 | : __ptr_(__u.release(), _VSTDstd::__1::forward<deleter_type>(__u.get_deleter())) { |
| 215 | } |
| 216 | |
| 217 | template <class _Up, class _Ep, |
| 218 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 219 | class = _EnableIfDeleterConvertible<_Ep> |
| 220 | > |
| 221 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 222 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPTnoexcept |
| 223 | : __ptr_(__u.release(), _VSTDstd::__1::forward<_Ep>(__u.get_deleter())) {} |
| 224 | |
| 225 | #if _LIBCPP_STD_VER14 <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
| 226 | template <class _Up> |
| 227 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 228 | unique_ptr(auto_ptr<_Up>&& __p, |
| 229 | typename enable_if<is_convertible<_Up*, _Tp*>::value && |
| 230 | is_same<_Dp, default_delete<_Tp> >::value, |
| 231 | __nat>::type = __nat()) _NOEXCEPTnoexcept |
| 232 | : __ptr_(__p.release(), __default_init_tag()) {} |
| 233 | #endif |
| 234 | |
| 235 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 236 | unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPTnoexcept { |
| 237 | reset(__u.release()); |
| 238 | __ptr_.second() = _VSTDstd::__1::forward<deleter_type>(__u.get_deleter()); |
| 239 | return *this; |
| 240 | } |
| 241 | |
| 242 | template <class _Up, class _Ep, |
| 243 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 244 | class = _EnableIfDeleterAssignable<_Ep> |
| 245 | > |
| 246 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 247 | unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPTnoexcept { |
| 248 | reset(__u.release()); |
| 249 | __ptr_.second() = _VSTDstd::__1::forward<_Ep>(__u.get_deleter()); |
| 250 | return *this; |
| 251 | } |
| 252 | |
| 253 | #if _LIBCPP_STD_VER14 <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) |
| 254 | template <class _Up> |
| 255 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 256 | typename enable_if<is_convertible<_Up*, _Tp*>::value && |
| 257 | is_same<_Dp, default_delete<_Tp> >::value, |
| 258 | unique_ptr&>::type |
| 259 | operator=(auto_ptr<_Up> __p) { |
| 260 | reset(__p.release()); |
| 261 | return *this; |
| 262 | } |
| 263 | #endif |
| 264 | |
| 265 | #ifdef _LIBCPP_CXX03_LANG |
| 266 | unique_ptr(unique_ptr const&) = delete; |
| 267 | unique_ptr& operator=(unique_ptr const&) = delete; |
| 268 | #endif |
| 269 | |
| 270 | |
| 271 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 272 | ~unique_ptr() { reset(); } |
| 273 | |
| 274 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 275 | unique_ptr& operator=(nullptr_t) _NOEXCEPTnoexcept { |
| 276 | reset(); |
| 277 | return *this; |
| 278 | } |
| 279 | |
| 280 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 281 | typename add_lvalue_reference<_Tp>::type |
| 282 | operator*() const { |
| 283 | return *__ptr_.first(); |
| 284 | } |
| 285 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 286 | pointer operator->() const _NOEXCEPTnoexcept { |
| 287 | return __ptr_.first(); |
| 288 | } |
| 289 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 290 | pointer get() const _NOEXCEPTnoexcept { |
| 291 | return __ptr_.first(); |
| 292 | } |
| 293 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 294 | deleter_type& get_deleter() _NOEXCEPTnoexcept { |
| 295 | return __ptr_.second(); |
| 296 | } |
| 297 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 298 | const deleter_type& get_deleter() const _NOEXCEPTnoexcept { |
| 299 | return __ptr_.second(); |
| 300 | } |
| 301 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 302 | explicit operator bool() const _NOEXCEPTnoexcept { |
| 303 | return __ptr_.first() != nullptr; |
| 304 | } |
| 305 | |
| 306 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 307 | pointer release() _NOEXCEPTnoexcept { |
| 308 | pointer __t = __ptr_.first(); |
| 309 | __ptr_.first() = pointer(); |
| 310 | return __t; |
| 311 | } |
| 312 | |
| 313 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 314 | void reset(pointer __p = pointer()) _NOEXCEPTnoexcept { |
| 315 | pointer __tmp = __ptr_.first(); |
| 316 | __ptr_.first() = __p; |
| 317 | if (__tmp) |
| 318 | __ptr_.second()(__tmp); |
| 319 | } |
| 320 | |
| 321 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 322 | void swap(unique_ptr& __u) _NOEXCEPTnoexcept { |
| 323 | __ptr_.swap(__u.__ptr_); |
| 324 | } |
| 325 | }; |
| 326 | |
| 327 | |
| 328 | template <class _Tp, class _Dp> |
| 329 | class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) unique_ptr<_Tp[], _Dp> { |
| 330 | public: |
| 331 | typedef _Tp element_type; |
| 332 | typedef _Dp deleter_type; |
| 333 | typedef typename __pointer<_Tp, deleter_type>::type pointer; |
| 334 | |
| 335 | private: |
| 336 | __compressed_pair<pointer, deleter_type> __ptr_; |
| 337 | |
| 338 | template <class _From> |
| 339 | struct _CheckArrayPointerConversion : is_same<_From, pointer> {}; |
| 340 | |
| 341 | template <class _FromElem> |
| 342 | struct _CheckArrayPointerConversion<_FromElem*> |
| 343 | : integral_constant<bool, |
| 344 | is_same<_FromElem*, pointer>::value || |
| 345 | (is_same<pointer, element_type*>::value && |
| 346 | is_convertible<_FromElem(*)[], element_type(*)[]>::value) |
| 347 | > |
| 348 | {}; |
| 349 | |
| 350 | typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE; |
| 351 | |
| 352 | template <bool _Dummy> |
| 353 | using _LValRefType _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = |
| 354 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type; |
| 355 | |
| 356 | template <bool _Dummy> |
| 357 | using _GoodRValRefType _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = |
| 358 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type; |
| 359 | |
| 360 | template <bool _Dummy> |
| 361 | using _BadRValRefType _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = |
| 362 | typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type; |
| 363 | |
| 364 | template <bool _Dummy, class _Deleter = typename __dependent_type< |
| 365 | __identity<deleter_type>, _Dummy>::type> |
| 366 | using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = |
| 367 | typename enable_if<is_default_constructible<_Deleter>::value && |
| 368 | !is_pointer<_Deleter>::value>::type; |
| 369 | |
| 370 | template <class _ArgType> |
| 371 | using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = |
| 372 | typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type; |
| 373 | |
| 374 | template <class _Pp> |
| 375 | using _EnableIfPointerConvertible _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename enable_if< |
| 376 | _CheckArrayPointerConversion<_Pp>::value |
| 377 | >::type; |
| 378 | |
| 379 | template <class _UPtr, class _Up, |
| 380 | class _ElemT = typename _UPtr::element_type> |
| 381 | using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename enable_if< |
| 382 | is_array<_Up>::value && |
| 383 | is_same<pointer, element_type*>::value && |
| 384 | is_same<typename _UPtr::pointer, _ElemT*>::value && |
| 385 | is_convertible<_ElemT(*)[], element_type(*)[]>::value |
| 386 | >::type; |
| 387 | |
| 388 | template <class _UDel> |
| 389 | using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename enable_if< |
| 390 | (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) || |
| 391 | (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) |
| 392 | >::type; |
| 393 | |
| 394 | template <class _UDel> |
| 395 | using _EnableIfDeleterAssignable _LIBCPP_NODEBUG_TYPE__attribute__((nodebug)) = typename enable_if< |
| 396 | is_assignable<_Dp&, _UDel&&>::value |
| 397 | >::type; |
| 398 | |
| 399 | public: |
| 400 | template <bool _Dummy = true, |
| 401 | class = _EnableIfDeleterDefaultConstructible<_Dummy> > |
| 402 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 403 | _LIBCPP_CONSTEXPRconstexpr unique_ptr() _NOEXCEPTnoexcept : __ptr_(pointer(), __default_init_tag()) {} |
| 404 | |
| 405 | template <bool _Dummy = true, |
| 406 | class = _EnableIfDeleterDefaultConstructible<_Dummy> > |
| 407 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 408 | _LIBCPP_CONSTEXPRconstexpr unique_ptr(nullptr_t) _NOEXCEPTnoexcept : __ptr_(pointer(), __default_init_tag()) {} |
| 409 | |
| 410 | template <class _Pp, bool _Dummy = true, |
| 411 | class = _EnableIfDeleterDefaultConstructible<_Dummy>, |
| 412 | class = _EnableIfPointerConvertible<_Pp> > |
| 413 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 414 | explicit unique_ptr(_Pp __p) _NOEXCEPTnoexcept |
| 415 | : __ptr_(__p, __default_init_tag()) {} |
| 416 | |
| 417 | template <class _Pp, bool _Dummy = true, |
| 418 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >, |
| 419 | class = _EnableIfPointerConvertible<_Pp> > |
| 420 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 421 | unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPTnoexcept |
| 422 | : __ptr_(__p, __d) {} |
| 423 | |
| 424 | template <bool _Dummy = true, |
| 425 | class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > > |
| 426 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 427 | unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPTnoexcept |
| 428 | : __ptr_(nullptr, __d) {} |
| 429 | |
| 430 | template <class _Pp, bool _Dummy = true, |
| 431 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >, |
| 432 | class = _EnableIfPointerConvertible<_Pp> > |
| 433 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 434 | unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPTnoexcept |
| 435 | : __ptr_(__p, _VSTDstd::__1::move(__d)) { |
| 436 | static_assert(!is_reference<deleter_type>::value, |
| 437 | "rvalue deleter bound to reference"); |
| 438 | } |
| 439 | |
| 440 | template <bool _Dummy = true, |
| 441 | class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > > |
| 442 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 443 | unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPTnoexcept |
| 444 | : __ptr_(nullptr, _VSTDstd::__1::move(__d)) { |
| 445 | static_assert(!is_reference<deleter_type>::value, |
| 446 | "rvalue deleter bound to reference"); |
| 447 | } |
| 448 | |
| 449 | template <class _Pp, bool _Dummy = true, |
| 450 | class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >, |
| 451 | class = _EnableIfPointerConvertible<_Pp> > |
| 452 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 453 | unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete; |
| 454 | |
| 455 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 456 | unique_ptr(unique_ptr&& __u) _NOEXCEPTnoexcept |
| 457 | : __ptr_(__u.release(), _VSTDstd::__1::forward<deleter_type>(__u.get_deleter())) { |
| 458 | } |
| 459 | |
| 460 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 461 | unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPTnoexcept { |
| 462 | reset(__u.release()); |
| 463 | __ptr_.second() = _VSTDstd::__1::forward<deleter_type>(__u.get_deleter()); |
| 464 | return *this; |
| 465 | } |
| 466 | |
| 467 | template <class _Up, class _Ep, |
| 468 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 469 | class = _EnableIfDeleterConvertible<_Ep> |
| 470 | > |
| 471 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 472 | unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPTnoexcept |
| 473 | : __ptr_(__u.release(), _VSTDstd::__1::forward<_Ep>(__u.get_deleter())) { |
| 474 | } |
| 475 | |
| 476 | template <class _Up, class _Ep, |
| 477 | class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>, |
| 478 | class = _EnableIfDeleterAssignable<_Ep> |
| 479 | > |
| 480 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 481 | unique_ptr& |
| 482 | operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPTnoexcept { |
| 483 | reset(__u.release()); |
| 484 | __ptr_.second() = _VSTDstd::__1::forward<_Ep>(__u.get_deleter()); |
| 485 | return *this; |
| 486 | } |
| 487 | |
| 488 | #ifdef _LIBCPP_CXX03_LANG |
| 489 | unique_ptr(unique_ptr const&) = delete; |
| 490 | unique_ptr& operator=(unique_ptr const&) = delete; |
| 491 | #endif |
| 492 | |
| 493 | public: |
| 494 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 495 | ~unique_ptr() { reset(); } |
| 496 | |
| 497 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 498 | unique_ptr& operator=(nullptr_t) _NOEXCEPTnoexcept { |
| 499 | reset(); |
| 500 | return *this; |
| 501 | } |
| 502 | |
| 503 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 504 | typename add_lvalue_reference<_Tp>::type |
| 505 | operator[](size_t __i) const { |
| 506 | return __ptr_.first()[__i]; |
| 507 | } |
| 508 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 509 | pointer get() const _NOEXCEPTnoexcept { |
| 510 | return __ptr_.first(); |
| 511 | } |
| 512 | |
| 513 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 514 | deleter_type& get_deleter() _NOEXCEPTnoexcept { |
| 515 | return __ptr_.second(); |
| 516 | } |
| 517 | |
| 518 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 519 | const deleter_type& get_deleter() const _NOEXCEPTnoexcept { |
| 520 | return __ptr_.second(); |
| 521 | } |
| 522 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 523 | explicit operator bool() const _NOEXCEPTnoexcept { |
| 524 | return __ptr_.first() != nullptr; |
| 525 | } |
| 526 | |
| 527 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 528 | pointer release() _NOEXCEPTnoexcept { |
| 529 | pointer __t = __ptr_.first(); |
| 530 | __ptr_.first() = pointer(); |
| 531 | return __t; |
| 532 | } |
| 533 | |
| 534 | template <class _Pp> |
| 535 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 536 | typename enable_if< |
| 537 | _CheckArrayPointerConversion<_Pp>::value |
| 538 | >::type |
| 539 | reset(_Pp __p) _NOEXCEPTnoexcept { |
| 540 | pointer __tmp = __ptr_.first(); |
| 541 | __ptr_.first() = __p; |
| 542 | if (__tmp) |
| 543 | __ptr_.second()(__tmp); |
| 544 | } |
| 545 | |
| 546 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 547 | void reset(nullptr_t = nullptr) _NOEXCEPTnoexcept { |
| 548 | pointer __tmp = __ptr_.first(); |
| 549 | __ptr_.first() = nullptr; |
| 550 | if (__tmp) |
| 551 | __ptr_.second()(__tmp); |
| 552 | } |
| 553 | |
| 554 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 555 | void swap(unique_ptr& __u) _NOEXCEPTnoexcept { |
| 556 | __ptr_.swap(__u.__ptr_); |
| 557 | } |
| 558 | |
| 559 | }; |
| 560 | |
| 561 | template <class _Tp, class _Dp> |
| 562 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 563 | typename enable_if< |
| 564 | __is_swappable<_Dp>::value, |
| 565 | void |
| 566 | >::type |
| 567 | swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPTnoexcept {__x.swap(__y);} |
| 568 | |
| 569 | template <class _T1, class _D1, class _T2, class _D2> |
| 570 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 571 | bool |
| 572 | operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();} |
| 573 | |
| 574 | template <class _T1, class _D1, class _T2, class _D2> |
| 575 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 576 | bool |
| 577 | operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);} |
| 578 | |
| 579 | template <class _T1, class _D1, class _T2, class _D2> |
| 580 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 581 | bool |
| 582 | operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) |
| 583 | { |
| 584 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 585 | typedef typename unique_ptr<_T2, _D2>::pointer _P2; |
| 586 | typedef typename common_type<_P1, _P2>::type _Vp; |
| 587 | return less<_Vp>()(__x.get(), __y.get()); |
| 588 | } |
| 589 | |
| 590 | template <class _T1, class _D1, class _T2, class _D2> |
| 591 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 592 | bool |
| 593 | operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;} |
| 594 | |
| 595 | template <class _T1, class _D1, class _T2, class _D2> |
| 596 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 597 | bool |
| 598 | operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);} |
| 599 | |
| 600 | template <class _T1, class _D1, class _T2, class _D2> |
| 601 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 602 | bool |
| 603 | operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);} |
| 604 | |
| 605 | template <class _T1, class _D1> |
| 606 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 607 | bool |
| 608 | operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPTnoexcept |
| 609 | { |
| 610 | return !__x; |
| 611 | } |
| 612 | |
| 613 | template <class _T1, class _D1> |
| 614 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 615 | bool |
| 616 | operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPTnoexcept |
| 617 | { |
| 618 | return !__x; |
| 619 | } |
| 620 | |
| 621 | template <class _T1, class _D1> |
| 622 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 623 | bool |
| 624 | operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPTnoexcept |
| 625 | { |
| 626 | return static_cast<bool>(__x); |
| 627 | } |
| 628 | |
| 629 | template <class _T1, class _D1> |
| 630 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 631 | bool |
| 632 | operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPTnoexcept |
| 633 | { |
| 634 | return static_cast<bool>(__x); |
| 635 | } |
| 636 | |
| 637 | template <class _T1, class _D1> |
| 638 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 639 | bool |
| 640 | operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 641 | { |
| 642 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 643 | return less<_P1>()(__x.get(), nullptr); |
| 644 | } |
| 645 | |
| 646 | template <class _T1, class _D1> |
| 647 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 648 | bool |
| 649 | operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 650 | { |
| 651 | typedef typename unique_ptr<_T1, _D1>::pointer _P1; |
| 652 | return less<_P1>()(nullptr, __x.get()); |
| 653 | } |
| 654 | |
| 655 | template <class _T1, class _D1> |
| 656 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 657 | bool |
| 658 | operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 659 | { |
| 660 | return nullptr < __x; |
| 661 | } |
| 662 | |
| 663 | template <class _T1, class _D1> |
| 664 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 665 | bool |
| 666 | operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 667 | { |
| 668 | return __x < nullptr; |
| 669 | } |
| 670 | |
| 671 | template <class _T1, class _D1> |
| 672 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 673 | bool |
| 674 | operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 675 | { |
| 676 | return !(nullptr < __x); |
| 677 | } |
| 678 | |
| 679 | template <class _T1, class _D1> |
| 680 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 681 | bool |
| 682 | operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 683 | { |
| 684 | return !(__x < nullptr); |
| 685 | } |
| 686 | |
| 687 | template <class _T1, class _D1> |
| 688 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 689 | bool |
| 690 | operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) |
| 691 | { |
| 692 | return !(__x < nullptr); |
| 693 | } |
| 694 | |
| 695 | template <class _T1, class _D1> |
| 696 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 697 | bool |
| 698 | operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) |
| 699 | { |
| 700 | return !(nullptr < __x); |
| 701 | } |
| 702 | |
| 703 | #if _LIBCPP_STD_VER14 > 11 |
| 704 | |
| 705 | template<class _Tp> |
| 706 | struct __unique_if |
| 707 | { |
| 708 | typedef unique_ptr<_Tp> __unique_single; |
| 709 | }; |
| 710 | |
| 711 | template<class _Tp> |
| 712 | struct __unique_if<_Tp[]> |
| 713 | { |
| 714 | typedef unique_ptr<_Tp[]> __unique_array_unknown_bound; |
| 715 | }; |
| 716 | |
| 717 | template<class _Tp, size_t _Np> |
| 718 | struct __unique_if<_Tp[_Np]> |
| 719 | { |
| 720 | typedef void __unique_array_known_bound; |
| 721 | }; |
| 722 | |
| 723 | template<class _Tp, class... _Args> |
| 724 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 725 | typename __unique_if<_Tp>::__unique_single |
| 726 | make_unique(_Args&&... __args) |
| 727 | { |
| 728 | return unique_ptr<_Tp>(new _Tp(_VSTDstd::__1::forward<_Args>(__args)...)); |
| 729 | } |
| 730 | |
| 731 | template<class _Tp> |
| 732 | inline _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 733 | typename __unique_if<_Tp>::__unique_array_unknown_bound |
| 734 | make_unique(size_t __n) |
| 735 | { |
| 736 | typedef typename remove_extent<_Tp>::type _Up; |
| 737 | return unique_ptr<_Tp>(new _Up[__n]()); |
| 738 | } |
| 739 | |
| 740 | template<class _Tp, class... _Args> |
| 741 | typename __unique_if<_Tp>::__unique_array_known_bound |
| 742 | make_unique(_Args&&...) = delete; |
| 743 | |
| 744 | #endif // _LIBCPP_STD_VER > 11 |
| 745 | |
| 746 | template <class _Tp> struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) hash; |
| 747 | |
| 748 | template <class _Tp, class _Dp> |
| 749 | #ifdef _LIBCPP_CXX03_LANG |
| 750 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) hash<unique_ptr<_Tp, _Dp> > |
| 751 | #else |
| 752 | struct _LIBCPP_TEMPLATE_VIS__attribute__ ((__type_visibility__("default"))) hash<__enable_hash_helper< |
| 753 | unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> > |
| 754 | #endif |
| 755 | { |
| 756 | #if _LIBCPP_STD_VER14 <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 757 | _LIBCPP_DEPRECATED_IN_CXX17 typedef unique_ptr<_Tp, _Dp> argument_type; |
| 758 | _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type; |
| 759 | #endif |
| 760 | |
| 761 | _LIBCPP_INLINE_VISIBILITY__attribute__ ((__visibility__("hidden"))) __attribute__ ((__exclude_from_explicit_instantiation__ )) |
| 762 | size_t operator()(const unique_ptr<_Tp, _Dp>& __ptr) const |
| 763 | { |
| 764 | typedef typename unique_ptr<_Tp, _Dp>::pointer pointer; |
| 765 | return hash<pointer>()(__ptr.get()); |
| 766 | } |
| 767 | }; |
| 768 | |
| 769 | _LIBCPP_END_NAMESPACE_STD} } |
| 770 | |
| 771 | _LIBCPP_POP_MACROSpop_macro("min") pop_macro("max") |
| 772 | |
| 773 | #endif // _LIBCPP___MEMORY_UNIQUE_PTR_H |