// map standard header
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#pragma once
#ifndef _MAP_
#define _MAP_
#include <yvals_core.h>
#if _STL_COMPILER_PREPROCESSOR
#include <tuple>
#include <xtree>
#if _HAS_CXX17
#include <xpolymorphic_allocator.h>
#endif // _HAS_CXX17
#pragma pack(push, _CRT_PACKING)
#pragma warning(push, _STL_WARNING_LEVEL)
#pragma warning(disable : _STL_DISABLED_WARNINGS)
_STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new
_STD_BEGIN
template <class _Alloc>
struct _Alloc_construct_ptr { // pointer used to help construct 1 _Alloc::value_type without EH
using pointer = _Alloc_ptr_t<_Alloc>;
_Alloc& _Al;
pointer _Ptr;
explicit _Alloc_construct_ptr(_Alloc& _Al_) : _Al(_Al_), _Ptr(nullptr) {}
pointer _Release() { return _STD exchange(_Ptr, nullptr); }
// disengage *this and return contained pointer 解除*this并返回包含的指针
void _Allocate() { _Ptr = nullptr; _Ptr = _Al.allocate(1); }
// disengage *this, then allocate a new memory block 解除这个,然后分配一个新的内存块
// if allocate throws, prevents double-free
~_Alloc_construct_ptr() { if (_Ptr) _Al.deallocate(_Ptr, 1); }
// if this instance is engaged, deallocate storage
_Alloc_construct_ptr(const _Alloc_construct_ptr&) = delete;
_Alloc_construct_ptr& operator=(const _Alloc_construct_ptr&) = delete;
};
template <class _Alnode>
struct _Tree_temp_node_alloc : _Alloc_construct_ptr<_Alnode>
{ // EH helper for _Tree_temp_node
explicit _Tree_temp_node_alloc(_Alnode& _Al_) : _Alloc_construct_ptr<_Alnode>(_Al_)
{ _Alloc_construct_ptr<_Alnode>::_Allocate(); }
_Tree_temp_node_alloc(const _Tree_temp_node_alloc&) = delete;
_Tree_temp_node_alloc& operator=(const _Tree_temp_node_alloc&) = delete;
};
template <class _Alnode>
struct _Tree_temp_node : _Tree_temp_node_alloc<_Alnode>
{ // temporarily stores a constructed tree node 临时存储构造的树节点
using _Alnode_traits = allocator_traits<_Alnode>;
using _Nodeptr = typename _Alnode_traits::pointer;
enum _Redbl { _Red, _Black };// colors for link to parent
template <class... _Valtys>
explicit _Tree_temp_node(_Alnode& _Al_, _Nodeptr _Myhead, _Valtys&&... _Vals)
: _Tree_temp_node_alloc<_Alnode>(_Al_)
{
_Alnode_traits::construct(this->_Al, _STD addressof(this->_Ptr->_Myval), _STD forward<_Valtys>(_Vals)...);
_Construct_in_place(this->_Ptr->_Left, _Myhead);
_Construct_in_place(this->_Ptr->_Parent, _Myhead);
_Construct_in_place(this->_Ptr->_Right, _Myhead);
this->_Ptr->_Color = _Red;
this->_Ptr->_Isnil = false;
}
_Tree_temp_node(const _Tree_temp_node&) = delete;
_Tree_temp_node& operator=(const _Tree_temp_node&) = delete;
~_Tree_temp_node()
{
if (this->_Ptr) {
_Destroy_in_place(this->_Ptr->_Left);
_Destroy_in_place(this->_Ptr->_Parent);
/*
template <class _Ty>
void destroy_at(_Ty* const _Location) {
if constexpr (is_array_v<_Ty>) _Destroy_range(_STD begin(*_Location), _STD end(*_Location));
else _Location->~_Ty();
}
template <class _Ty>
void _Destroy_in_place(_Ty& _Obj) {
if constexpr (is_array_v<_Ty>) _Destroy_range(_Obj, _Obj + extent_v<_Ty>);
else _Obj.~_Ty();
}
template <class _Alloc>
struct _Default_allocator_traits
{
template <class _Uty>
static void destroy(_Alloc&, _Uty* const _Ptr) { _STD destroy_at(_Ptr); }
};
*/
_Destroy_in_place(this->_Ptr->_Right);
_Alnode_traits::destroy(this->_Al, _STD addressof(this->_Ptr->_Myval));
}
}
};
//-----------------------------------------------------------------------------------
template <class _Alnode, class _Scary_val>
struct _Tree_head_scoped_ptr
{ // temporary storage for allocated node pointers to ensure exception safety
//为确保异常安全而分配的节点指针的临时存储
_Alnode& _Al;
_Scary_val* _Mycont;
_Tree_head_scoped_ptr(_Alnode& _Al_, _Scary_val& _Mycont_) : _Al(_Al_), _Mycont(_STD addressof(_Mycont_))
{ _Mycont->_Myhead = _Alnode::value_type::_Buyheadnode(_Al); }
void _Release() { _Mycont = nullptr; }
~_Tree_head_scoped_ptr() { if (_Mycont) _Mycont->_Erase_head(_Al); }
};
//-----------------------------------------------------------------------------------
/*
struct _Iterator_base0
{
void _Adopt(const void*) {}
const _Container_base0* _Getcont() { return nullptr; }
static bool _Unwrap_when_unverified = true;
};
*/
template <class _Mytree, class _Base = _Iterator_base0>
class _Tree_unchecked_const_iterator : public _Base {
public:
using iterator_category = bidirectional_iterator_tag;
using _Nodeptr = typename _Mytree::_Nodeptr;
using value_type = typename _Mytree::value_type;
using difference_type = typename _Mytree::difference_type;
using pointer = typename _Mytree::const_pointer;
using reference = const value_type&;
_Nodeptr _Ptr; // pointer to node
_Tree_unchecked_const_iterator() noexcept : _Ptr() {}
_Tree_unchecked_const_iterator(_Nodeptr _Pnode, const _Mytree* _Plist) : _Ptr(_Pnode)
{ this->_Adopt(_Plist); }
/*
struct _Iterator_base12 {
bool _Unwrap_when_unverified = _ITERATOR_DEBUG_LEVEL == 0;
mutable _Container_proxy* _Myproxy = nullptr;
mutable _Iterator_base12* _Mynextiter = nullptr;
void _Adopt_unlocked(const _Container_base12* _Parent) noexcept {
if (!_Parent) {
_Orphan_me_unlocked_v3();
return;
}
_Container_proxy* _Parent_proxy = _Parent->_Myproxy;
if (_Myproxy != _Parent_proxy) { // change parentage
if (_Myproxy) _Orphan_me_unlocked_v3(); // adopted, remove self from list
_Mynextiter = _Parent_proxy->_Myfirstiter;
_Parent_proxy->_Myfirstiter = this;
_Myproxy = _Parent_proxy;
}
}
void _Adopt_locked(const _Container_base12* _Parent) {
_Lockit _Lock(_LOCK_DEBUG);
_Adopt_unlocked(_Parent);
}
void _Adopt(const _Container_base12* _Parent) {
if (_STD is_constant_evaluated()) _Adopt_unlocked(_Parent);
else _Adopt_locked(_Parent);
}
};
*/
reference operator*() { return _Ptr->_Myval; }
/*
template <class _Value_type, class _Voidptr>
struct _Tree_node
using value_type = _Value_type;
value_type _Myval;
};
template <class _Kty, class _Ty, class _Pr, class _Alloc, bool _Mfl>
class _Tmap_traits
{public:
using key_type = _Kty;
using value_type = pair<const _Kty, _Ty>;
using node_type = _Node_handle<_Tree_node<value_type, typename allocator_traits<_Alloc>::void_pointer>,
_Alloc, _Node_handle_map_base, _Kty, _Ty>;
};
template <class _Kty, class _Ty, class _Pr = less<_Kty>, class _Alloc = allocator<pair<const _Kty, _Ty>>>
class map : public _Tree<_Tmap_traits<_Kty, _Ty, _Pr, _Alloc, false>> {};
*/
/*
对 **this 的解读为调用 reference operator*() {return this->_Ptr->_Myval;}
*/
/*
template <class _Ty>
struct pointer_traits {
没有合适的资源?快使用搜索试试~ 我知道了~
vs2019 cpp 20规范 智能指针和STL常用容器类模板的源码注释
共35个文件
cpp:33个
hpp:1个
h:1个
0 下载量 189 浏览量
2023-09-12
16:26:55
上传
评论
收藏 416KB RAR 举报
温馨提示
vs2019 cpp 20规范 智能指针和STL常用容器类模板的源码注释
资源推荐
资源详情
资源评论
收起资源包目录
vs2019 cpp 20规范 智能指针和STL常用容器类模板的源码注释.rar (35个子文件)
vs2019 cpp 20规范 智能指针和STL常用容器类模板的源码注释
c++源码
c++之std_function的源码相关分析.cpp 9KB
std之ref()及cref()及reference_wrapper源码分析_.cpp 4KB
tuple详解版.h 20KB
未完成
vector《bool》的源码分析.cpp 46KB
类thread源码分析.cpp 13KB
c++的declval的源码分析.cpp 528B
boost库源码分析
源码分析boost库之stl_type_index.hpp 7KB
STL容器相关类源码分析
array源码分析和reverse_iterator和_Array_const_iterator.cpp 30KB
vector析.cpp 487KB
_Compressed_pair源码分析.cpp 2KB
源码分析类initializer_list .cpp 700B
list析.cpp 481KB
分析_Iterator_base12与_Container_base12与_Container_proxy.cpp 11KB
unordered_set源码分析.cpp 588KB
set源码分析.cpp 462KB
initializer_list分析.cpp 713B
stack源码分析.cpp 24KB
map.cpp 684KB
queue源码分析.cpp 103KB
系统默认分配器 allocate 的源码分析.cpp 3KB
unordered_map源码分析.cpp 617KB
forward_list源码分析.cpp 475KB
分析_Container_proxy_ptr与_Container_proxy_ptr12.cpp 4KB
deque析.cpp 337KB
c++智能指针源码
c++智能指针源码auto_ptr.cpp 3KB
智能指针源码memory之_Ptr_base.cpp 7KB
文件xmemory之allocator.cpp 5KB
指针源码memory文件之_Ref_count_base与其子类_Ref_count和_Ref_count_resource.cpp 4KB
指针源码unique_ptr 与 unique_ptr【】与make_unique.cpp 17KB
c++智能指针weak_ptr源码分析.cpp 5KB
文件xmemory之_Default_allocator_traits.cpp 5KB
指针源码memory之shared_ptr与default_delete.cpp 31KB
c++指针源码memory之_Ref_count_obj2 和STD forward 和 STD make_shared.cpp 8KB
文件xmemory之_Normal_allocator_traits.cpp 13KB
文件memory之_Ref_count_resource_alloc.cpp 6KB
共 35 条
- 1
资源评论
zhangzhangkeji
- 粉丝: 99
- 资源: 42
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功