当前位置: 首页 > news >正文

shared_ptr

源码路径:

/opt/rh/devtoolset-10/root/usr/include/c++/10/bits/shared_ptr_base.h

D:\wsl-ubuntu20.04\rootfs\usr\include\c++\9\bits\shared_ptr_base.h

类原型:

    template<typename _Tp, _Lock_policy _Lp>class __shared_ptr: public __shared_ptr_access<_Tp, _Lp>{public:using element_type = typename remove_extent<_Tp>::type;private:// Constraint for taking ownership of a pointer of type _Yp*:template<typename _Yp>using _SafeConv= typename enable_if<__sp_is_constructible<_Tp, _Yp>::value>::type;// Constraint for construction from shared_ptr and weak_ptr:template<typename _Yp, typename _Res = void>using _Compatible = typenameenable_if<__sp_compatible_with<_Yp*, _Tp*>::value, _Res>::type;// Constraint for assignment from shared_ptr and weak_ptr:template<typename _Yp>using _Assignable = _Compatible<_Yp, __shared_ptr&>;// Constraint for construction from unique_ptr:template<typename _Yp, typename _Del, typename _Res = void,typename _Ptr = typename unique_ptr<_Yp, _Del>::pointer>using _UniqCompatible = typename enable_if<__and_<__sp_compatible_with<_Yp*, _Tp*>, is_convertible<_Ptr, element_type*>>::value, _Res>::type;// Constraint for assignment from unique_ptr:template<typename _Yp, typename _Del>using _UniqAssignable = _UniqCompatible<_Yp, _Del, __shared_ptr&>;public:#if __cplusplus > 201402Lusing weak_type = __weak_ptr<_Tp, _Lp>;
#endifconstexpr __shared_ptr() noexcept: _M_ptr(0), _M_refcount(){ }template<typename _Yp, typename = _SafeConv<_Yp>>explicit__shared_ptr(_Yp* __p): _M_ptr(__p), _M_refcount(__p, typename is_array<_Tp>::type()){static_assert( !is_void<_Yp>::value, "incomplete type" );static_assert( sizeof(_Yp) > 0, "incomplete type" );_M_enable_shared_from_this_with(__p);}template<typename _Yp, typename _Deleter, typename = _SafeConv<_Yp>>__shared_ptr(_Yp* __p, _Deleter __d): _M_ptr(__p), _M_refcount(__p, std::move(__d)){static_assert(__is_invocable<_Deleter&, _Yp*&>::value,"deleter expression d(p) is well-formed");_M_enable_shared_from_this_with(__p);}template<typename _Yp, typename _Deleter, typename _Alloc,typename = _SafeConv<_Yp>>__shared_ptr(_Yp* __p, _Deleter __d, _Alloc __a): _M_ptr(__p), _M_refcount(__p, std::move(__d), std::move(__a)){static_assert(__is_invocable<_Deleter&, _Yp*&>::value,"deleter expression d(p) is well-formed");_M_enable_shared_from_this_with(__p);}template<typename _Deleter>__shared_ptr(nullptr_t __p, _Deleter __d): _M_ptr(0), _M_refcount(__p, std::move(__d)){ }template<typename _Deleter, typename _Alloc>__shared_ptr(nullptr_t __p, _Deleter __d, _Alloc __a): _M_ptr(0), _M_refcount(__p, std::move(__d), std::move(__a)){ }template<typename _Yp>__shared_ptr(const __shared_ptr<_Yp, _Lp>& __r,element_type* __p) noexcept: _M_ptr(__p), _M_refcount(__r._M_refcount) // never throws{ }__shared_ptr(const __shared_ptr&) noexcept = default;__shared_ptr& operator=(const __shared_ptr&) noexcept = default;~__shared_ptr() = default;template<typename _Yp, typename = _Compatible<_Yp>>__shared_ptr(const __shared_ptr<_Yp, _Lp>& __r) noexcept: _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount){ }__shared_ptr(__shared_ptr&& __r) noexcept: _M_ptr(__r._M_ptr), _M_refcount(){_M_refcount._M_swap(__r._M_refcount);__r._M_ptr = 0;}template<typename _Yp, typename = _Compatible<_Yp>>__shared_ptr(__shared_ptr<_Yp, _Lp>&& __r) noexcept: _M_ptr(__r._M_ptr), _M_refcount(){_M_refcount._M_swap(__r._M_refcount);__r._M_ptr = 0;}template<typename _Yp, typename = _Compatible<_Yp>>explicit __shared_ptr(const __weak_ptr<_Yp, _Lp>& __r): _M_refcount(__r._M_refcount) // may throw{// It is now safe to copy __r._M_ptr, as// _M_refcount(__r._M_refcount) did not throw._M_ptr = __r._M_ptr;}// If an exception is thrown this constructor has no effect.template<typename _Yp, typename _Del,typename = _UniqCompatible<_Yp, _Del>>__shared_ptr(unique_ptr<_Yp, _Del>&& __r): _M_ptr(__r.get()), _M_refcount(){auto __raw = __to_address(__r.get());_M_refcount = __shared_count<_Lp>(std::move(__r));_M_enable_shared_from_this_with(__raw);}#if __cplusplus <= 201402L && _GLIBCXX_USE_DEPRECATEDprotected:// If an exception is thrown this constructor has no effect.template<typename _Tp1, typename _Del,typename enable_if<__and_<__not_<is_array<_Tp>>, is_array<_Tp1>,is_convertible<typename unique_ptr<_Tp1, _Del>::pointer, _Tp*>>::value, bool>::type = true>__shared_ptr(unique_ptr<_Tp1, _Del>&& __r, __sp_array_delete): _M_ptr(__r.get()), _M_refcount(){auto __raw = __to_address(__r.get());_M_refcount = __shared_count<_Lp>(std::move(__r));_M_enable_shared_from_this_with(__raw);}public:
#endif#if _GLIBCXX_USE_DEPRECATED
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"// Postcondition: use_count() == 1 and __r.get() == 0template<typename _Yp, typename = _Compatible<_Yp>>__shared_ptr(auto_ptr<_Yp>&& __r);
#pragma GCC diagnostic pop
#endifconstexpr __shared_ptr(nullptr_t) noexcept : __shared_ptr() { }template<typename _Yp>_Assignable<_Yp>operator=(const __shared_ptr<_Yp, _Lp>& __r) noexcept{_M_ptr = __r._M_ptr;_M_refcount = __r._M_refcount; // __shared_count::op= doesn't throwreturn *this;}#if _GLIBCXX_USE_DEPRECATED
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"template<typename _Yp>_Assignable<_Yp>operator=(auto_ptr<_Yp>&& __r){__shared_ptr(std::move(__r)).swap(*this);return *this;}
#pragma GCC diagnostic pop
#endif__shared_ptr&operator=(__shared_ptr&& __r) noexcept{__shared_ptr(std::move(__r)).swap(*this);return *this;}template<class _Yp>_Assignable<_Yp>operator=(__shared_ptr<_Yp, _Lp>&& __r) noexcept{__shared_ptr(std::move(__r)).swap(*this);return *this;}template<typename _Yp, typename _Del>_UniqAssignable<_Yp, _Del>operator=(unique_ptr<_Yp, _Del>&& __r){__shared_ptr(std::move(__r)).swap(*this);return *this;}voidreset() noexcept{ __shared_ptr().swap(*this); }template<typename _Yp>_SafeConv<_Yp>reset(_Yp* __p) // _Yp must be complete.{// Catch self-reset errors.__glibcxx_assert(__p == 0 || __p != _M_ptr);__shared_ptr(__p).swap(*this);}template<typename _Yp, typename _Deleter>_SafeConv<_Yp>reset(_Yp* __p, _Deleter __d){ __shared_ptr(__p, std::move(__d)).swap(*this); }template<typename _Yp, typename _Deleter, typename _Alloc>_SafeConv<_Yp>reset(_Yp* __p, _Deleter __d, _Alloc __a){ __shared_ptr(__p, std::move(__d), std::move(__a)).swap(*this); }element_type*get() const noexcept{ return _M_ptr; }explicit operator bool() const // never throws{ return _M_ptr == 0 ? false : true; }boolunique() const noexcept{ return _M_refcount._M_unique(); }longuse_count() const noexcept{ return _M_refcount._M_get_use_count(); }voidswap(__shared_ptr<_Tp, _Lp>& __other) noexcept{std::swap(_M_ptr, __other._M_ptr);_M_refcount._M_swap(__other._M_refcount);}template<typename _Tp1>boolowner_before(__shared_ptr<_Tp1, _Lp> const& __rhs) const noexcept{ return _M_refcount._M_less(__rhs._M_refcount); }template<typename _Tp1>boolowner_before(__weak_ptr<_Tp1, _Lp> const& __rhs) const noexcept{ return _M_refcount._M_less(__rhs._M_refcount); }protected:// This constructor is non-standard, it is used by allocate_shared.template<typename _Alloc, typename... _Args>__shared_ptr(_Sp_alloc_shared_tag<_Alloc> __tag, _Args&&... __args): _M_ptr(), _M_refcount(_M_ptr, __tag, std::forward<_Args>(__args)...){ _M_enable_shared_from_this_with(_M_ptr); }template<typename _Tp1, _Lock_policy _Lp1, typename _Alloc,typename... _Args>friend __shared_ptr<_Tp1, _Lp1>__allocate_shared(const _Alloc& __a, _Args&&... __args);// This constructor is used by __weak_ptr::lock() and// shared_ptr::shared_ptr(const weak_ptr&, std::nothrow_t).__shared_ptr(const __weak_ptr<_Tp, _Lp>& __r, std::nothrow_t): _M_refcount(__r._M_refcount, std::nothrow){_M_ptr = _M_refcount._M_get_use_count() ? __r._M_ptr : nullptr;}friend class __weak_ptr<_Tp, _Lp>;private:template<typename _Yp>using __esft_base_t = decltype(__enable_shared_from_this_base(std::declval<const __shared_count<_Lp>&>(),std::declval<_Yp*>()));// Detect an accessible and unambiguous enable_shared_from_this base.template<typename _Yp, typename = void>struct __has_esft_base: false_type { };template<typename _Yp>struct __has_esft_base<_Yp, __void_t<__esft_base_t<_Yp>>>: __not_<is_array<_Tp>> { }; // No enable shared_from_this for arraystemplate<typename _Yp, typename _Yp2 = typename remove_cv<_Yp>::type>typename enable_if<__has_esft_base<_Yp2>::value>::type_M_enable_shared_from_this_with(_Yp* __p) noexcept{if (auto __base = __enable_shared_from_this_base(_M_refcount, __p))__base->_M_weak_assign(const_cast<_Yp2*>(__p), _M_refcount);}template<typename _Yp, typename _Yp2 = typename remove_cv<_Yp>::type>typename enable_if<!__has_esft_base<_Yp2>::value>::type_M_enable_shared_from_this_with(_Yp*) noexcept{ }void*_M_get_deleter(const std::type_info& __ti) const noexcept{ return _M_refcount._M_get_deleter(__ti); }template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr;template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr;template<typename _Del, typename _Tp1, _Lock_policy _Lp1>friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&) noexcept;template<typename _Del, typename _Tp1>friend _Del* get_deleter(const shared_ptr<_Tp1>&) noexcept;element_type*	   _M_ptr;         // Contained pointer.__shared_count<_Lp>  _M_refcount;    // Reference counter.};

 

相关文章:

shared_ptr

源码路径&#xff1a; /opt/rh/devtoolset-10/root/usr/include/c/10/bits/shared_ptr_base.h D:\wsl-ubuntu20.04\rootfs\usr\include\c\9\bits\shared_ptr_base.h 类原型&#xff1a; template<typename _Tp, _Lock_policy _Lp>class __shared_ptr: public __shared_pt…...

ChatGPT + Stable Diffusion + 百度AI + MoviePy 实现文字生成视频,小说转视频,自媒体神器!(二)

ChatGPT Stable Diffusion 百度AI MoviePy 实现文字生成视频&#xff0c;小说转视频&#xff0c;自媒体神器&#xff01;(二) 前言 最近大模型频出&#xff0c;但是对于我们普通人来说&#xff0c;如何使用这些AI工具来辅助我们的工作呢&#xff0c;或者参与进入我们的生活…...

git提交的时候Changes not staged for commit

git删除和修改一些文件之后&#xff0c;git add -A之后就使用git commit -m "提交最新代码"后报错 On branch master Your branch is up to date with origin/master.Changes not staged for commit:但是使用git push origin master怎么都提交不上去&#xff0c;解决…...

03_使用execle表生成甘特图

背景 每次排期都需要话很多时间 很可能排期还不对头 这时候需要一个表能看到 1.什么时候项目结束 开始 转阶段 2.当前手上的活能不能做完 当前阶段手上有多少活 3.产品经理每次修改完计划迅速排期 甘特图生成 execle表生成 1.需要使用亿图创建甘特图 2.把当前的甘特图数据进…...

linux基础命令-ls

“ls” 命令是 Linux 系统中用来列出目录内容的常用命令。它显示当前工作目录中的文件和子目录列表。下面将详细解释 “ls” 命令的用法以及示例&#xff1a; 命令语法&#xff1a; ls [选项] [目录] 常用选项&#xff1a; -l&#xff1a; 以长格式&#xff08;long format&a…...

Chrome浏览器中的vue插件devtools的下载方式(使用Chrome应用商店/科学上网情况下)

目录 devtools对前端来说的好处——开发预览、远程调试、性能调优、Bug跟踪、断点调试等 下载步骤&#xff1a; 测试阶段&#xff1a; 最近做项目要使用devtools这个vue插件。 devtools对前端来说的好处——开发预览、远程调试、性能调优、Bug跟踪、断点调试等 下载步骤…...

7、Kubernetes核心技术 - Secret

目录 一、Secret概述 二、Secret 三种类型 2.1、Opaque 2..2、kubernetes.io/dockerconfigjson 2.3、kubernetes.io/service-account-token 三、Secret创建 3.1、命令行方式创建 Secret 3.2、yaml方式创建 Secret 四、Secret解码 五、Secret使用 5.1、将 Secret 挂载…...

MATLAB算法实战应用案例精讲-【自动驾驶】路径规划(补充篇)

目录 前言 几个高频面试题目 无人车运动规划,路径规划,轨迹规划的区别和联系?...

农业与太阳能的互利共生

不断增长的人口需要更多的食物和能源&#xff0c;而这些都在争夺有限的空间……除非能改变这样的竞争局面。 农业光伏装置将农业和太阳能生产结合起来。 农业光伏 (AV) 是 20 世纪 80 年代提出的概念&#xff0c;它在同一块土地上将农业和太阳能生产结合起来。 从业者在太阳能…...

每日一题(822. 翻转卡片游戏)-集合set

题目 822. 翻转卡片游戏 题解思路 简述为&#xff1a;找到桌面卡片中 不重复的最小值&#xff0c;卡片可以来回反转 如果 卡片前面后面的数字相同 则抛弃不用在剩下的卡片中 找到最小值&#xff08;前后可以反转 卡片不分前后&#xff09; 代码 C class Solution { pub…...

windows服务器iis PHP套件出现FastCGI等错误解决方法汇总

如果您的服务器安装了PHP套件&#xff0c;出现了无法打开的情况&#xff0c;请参照如下办法解决&#xff1a; 首先&#xff0c;需要设置IIS允许输出详细的错误信息到浏览器&#xff0c;才好具体分析 错误一&#xff1a; 处理程序“FastCGI”在其模块列表中有一个错误模块“Fast…...

Qt Creator 11 开放源码集成开发环境新增集成终端和 GitHub Copilot 支持

导读Qt 项目今天发布了 Qt Creator 11&#xff0c;这是一款开源、免费、跨平台 IDE&#xff08;集成开发环境&#xff09;软件的最新稳定版本&#xff0c;适用于 GNU/Linux、macOS 和 Windows 平台。 Qt Creator 11 的亮点包括支持标签、多外壳、颜色和字体的集成终端模拟器&am…...

Collections工具类(java)

文章目录 7.1 常用方法 参考操作数组的工具类&#xff1a;Arrays&#xff0c;Collections 是一个操作 Set、List 和 Map 等集合的工具类。 7.1 常用方法 Collections 中提供了一系列静态的方法对集合元素进行排序、查询和修改等操作&#xff0c;还提供了对集合对象设置不可变、…...

C++ 第六弹 STL

目录 1.什么是stl 2.六大组件-容器-序列式容器-C98 string 3.六大组件-容器-序列式容器-C98 vector 4.六大组件-容器-序列式容器-C98 list 5.六大组件-容器-序列式容器-C98 deque 6.六大组件-容器-序列式容器-C11 array 7.六大组件-容器-序列式容器-C11 forward_list 8…...

蓝桥杯上岸每日N题 第四期(最少刷题数)!!!

蓝桥杯上岸每日N题第四期 ❗️ ❗️ ❗️ 最少刷题数 同步收录 &#x1f447; 蓝桥杯上岸必背&#xff01;&#xff01;&#xff01;(持续更新中~) 大家好 我是寸铁&#x1f4aa; 冲刺蓝桥杯省一模板大全来啦 &#x1f525; 蓝桥杯4月8号就要开始了 &#x1f64f; 距离蓝…...

STM32 LWIP UDP 一对一 一对多发送

STM32 LWIP UDP通信 前言设置 IP 地址UDP函数配置实验结果单播发送&#xff0c;一对一发送广播发送&#xff0c;一对多发送 可能遇到的问题总结 前言 之前没有接触过网络的通信&#xff0c;工作需要 UDP 接收和发送通信&#xff0c;在网上没有找到一对一、一对多的相关例程&am…...

【有趣的设计模式】23 种设计模式详解和场景分析

前言 七大设计原则 1、单一原则&#xff1a;一个类只负责一个职责 2、开闭原则&#xff1a;对修改关闭&#xff0c;对扩展开放 3、里氏替换原则&#xff1a;不要破坏继承关系 4、接口隔离原则&#xff1a;暴露最小接口&#xff0c;避免接口过于臃肿 5、依赖倒置原则&#xff1…...

【数据结构与算法】TypeScript 实现图结构

class Grapg<T> {// 用于存储所有的顶点verteces: T[] [];// 用于存储所有的边 采用邻接表的形式adjList: Map<T, T[]> new Map();// 添加顶点addVertex(v: T) {this.verteces.push(v);// 初始化顶点的邻接表this.adjList.set(v, []);}// 添加边addEdge(v: T, w:…...

《golang设计模式》第一部分·创建型模式-04-抽象工厂模式(Abstract Factory)

文章目录 1. 概述1.1 角色1.2 类图 2. 代码示例2.1 设计2.2 代码2.3 类图 1. 概述 1.1 角色 AbstractFactory&#xff08;抽象工厂&#xff09;&#xff1a;它声明了一组用于创建产品的方法&#xff0c;每一个方法对应一种产品。ConcreteFactory&#xff08;具体工厂&#xf…...

改进粒子群算法优化BP神经网络---回归+分类两种案例

今天采用改进的粒子群算法(LPSO)优化算法优化BP神经网络。本文选用的LPSO算法是之前作者写过的一篇文章&#xff1a;基于改进莱维飞行和混沌映射&#xff08;10种混沌映射随意切换&#xff09;的粒子群优化算法&#xff0c;附matlab代码 文章一次性讲解两种案例&#xff0c;回归…...

VSCode配置PyTorch开发环境:从CUDA版本检查到镜像源加速(附常见报错解决方案)

VSCode配置PyTorch开发环境&#xff1a;从CUDA版本检查到镜像源加速&#xff08;附常见报错解决方案&#xff09; 在深度学习领域&#xff0c;PyTorch凭借其动态计算图和易用性已成为研究者和开发者的首选框架。然而&#xff0c;配置PyTorch开发环境时&#xff0c;CUDA版本匹配…...

如何快速搭建QQ机器人:OpenShamrock的终极指南

如何快速搭建QQ机器人&#xff1a;OpenShamrock的终极指南 【免费下载链接】OpenShamrock A Bot Framework based on Xposed with OneBot11 项目地址: https://gitcode.com/gh_mirrors/op/OpenShamrock OpenShamrock是一款基于LSPosed框架实现的QQ机器人开发框架&#x…...

【实战指南】League Akari:英雄联盟智能工具全解析

【实战指南】League Akari&#xff1a;英雄联盟智能工具全解析 【免费下载链接】League-Toolkit An all-in-one toolkit for LeagueClient. Gathering power &#x1f680;. 项目地址: https://gitcode.com/gh_mirrors/le/League-Toolkit 一、价值定位&#xff1a;重新定…...

AI 大模型落地系列|Eino ADK体系篇:你对 ChatModelAgent 有了解吗?

声明&#xff1a;本文源于官方文档&#xff0c;重点参考 Eino ADK: ChatModelAgent、Eino ADK: 概述、Eino ADK: Agent 协作 为什么很多人把 ChatModelAgent 想简单了&#xff1f;一文讲透 ReAct、Transfer、AgentAsTool 与 Middleware1. 为什么很多人会把 ChatModelAgent 想简…...

威联通NAS安全防护全攻略:10个必做设置让你的数据固若金汤

威联通NAS安全防护全攻略&#xff1a;10个必做设置让你的数据固若金汤 在数字化时代&#xff0c;数据安全已成为个人和企业最关注的议题之一。威联通NAS作为专业级网络存储设备&#xff0c;凭借其强大的硬件性能和丰富的软件生态&#xff0c;成为许多用户存储重要数据的首选。然…...

高效代码分析利器:cloc工具全场景使用指南

1. 为什么你需要cloc这个代码统计神器 第一次接手一个遗留项目时&#xff0c;我盯着密密麻麻的目录树发愁&#xff1a;这堆代码到底有多少实际内容&#xff1f;注释占比多少&#xff1f;不同语言的文件各有多少&#xff1f;直到同事推荐了cloc工具&#xff0c;输入一行命令就得…...

从Prompt到成稿|像素剧本圣殿输入剧情大纲→输出标准剧本全流程

从Prompt到成稿&#xff5c;像素剧本圣殿输入剧情大纲→输出标准剧本全流程 1. 工具介绍&#xff1a;像素剧本圣殿 像素剧本圣殿是一款基于Qwen2.5-14B-Instruct大模型深度优化的专业剧本创作工具。它将先进的AI文本生成能力与独特的8-Bit复古视觉风格相结合&#xff0c;为编…...

告别人工筛选!用Word2vec构建主题词库,我们拿“网络暴力”关键词试了试

智能主题词库构建实战&#xff1a;用Word2vec挖掘语义关联词汇 在信息爆炸的时代&#xff0c;内容运营和产品经理们常常面临一个共同挑战&#xff1a;如何从海量文本中快速识别和归类相关主题内容。传统的人工筛选方法不仅效率低下&#xff0c;还容易遗漏那些变体表达和新兴网络…...

D3KeyHelper:暗黑3效率提升工具的全方位应用指南

D3KeyHelper&#xff1a;暗黑3效率提升工具的全方位应用指南 【免费下载链接】D3keyHelper D3KeyHelper是一个有图形界面&#xff0c;可自定义配置的暗黑3鼠标宏工具。 项目地址: https://gitcode.com/gh_mirrors/d3/D3keyHelper D3KeyHelper是一款开源的暗黑3鼠标宏工具…...

别再死记硬背了!用FPGA和Verilog HDL手把手带你玩转数字电路设计(附避坑指南)

用FPGA和Verilog HDL玩转数字电路设计&#xff1a;从理论到实战的避坑指南 数字电路设计常常让初学者感到抽象和枯燥——真值表、状态机、时序约束这些概念看似冰冷&#xff0c;但当你亲手用FPGA开发板点亮第一个LED时&#xff0c;一切都会变得生动起来。本文将带你用Xilinx Ar…...