草庐IT

auto_ptr_ref

全部标签

c++ - 让 shared_ptr 成员破坏 CopyConstructible 契约吗?

我刚刚在codereview争论过其中声明具有std::shared_ptr成员的类会破坏CopyConstructible契约(Contract),特别是:ThefollowingexpressionsmustbevalidandhavetheirspecifiedeffectsTu=v;Thevalueofvisunchanged原因是复制会通过增加shared_ptr的引用计数来更改源对象,但我的反对意见是引用计数与shared_ptr。更改引用计数是一种副作用,但引用并未说明禁止在被复制的对象之外产生副作用。但我不是语言律师,所以我可能是错的。根据C++标准,什么是正确的?

【Vue3】使用ref与reactive创建响应式对象

💗💗💗欢迎来到我的博客,你将找到有关如何使用技术解决问题的文章,也会找到某个技术的学习路线。无论你是何种职业,我都希望我的博客对你有所帮助。最后不要忘记订阅我的博客以获取最新文章,也欢迎在文章下方留下你的评论和反馈。我期待着与你分享知识、互相学习和建立一个积极的社区。谢谢你的光临,让我们一起踏上这个知识之旅!文章目录🍋介绍ref🍋介绍reactive🍋ref扩展🍋ref和reactive对比🍋总结🍋介绍ref先来简单介绍一下ref,它可以定义响应式的变量语法:letxxx=ref(初始值)。**返回值:**一个RefImpl的实例对象,简称ref对象或ref,ref对象的value属性是响应式

使用 unique_ptr 包含 char 数组的 C++ 对象

我正在寻找一种方法来使用unique_ptr来分配一个结构,该结构包含一个char数组,其中包含动态设置的字节数以支持不同类型的消息。假设:structMyMessage{uint32_tid;uint32_tdata_size;chardata[4];};如何将下面的send_message()转换为使用智能指针?voidsend_message(void*data,constsize_tdata_size){constautomessage_size=sizeof(MyMessage)-4+data_size;constautomsg=reinterpret_cast(newcha

c++ - unique_ptr 作为模板参数

为什么要在VS2017中编译?#include#includeusingnamespacestd;structx{x(){coutvoidfoo(T&&item){structboo{Titem;boo(T&&t):item(std::move(t)){}};newboo(std::move(item));}intmain(){std::unique_ptrb(newx);foo(b);//IwouldexpectthatIshouldputstd::move(b)here.}按照编写的代码,输出是x()~x()如果foo(b)行写为foo(std::move(b)),那么输出就是x(

c++14 static constexpr auto 与 odr 用法

我有以下C++14代码:templatestructTest{staticconstexprautosomething{T::foo()};};这很好,只要T::foo()也是一个constexpr。现在我知道something是ODR使用的,所以我需要提供命名空间声明。我应该使用什么语法?templateconstexprautoTest::something;不起作用。谢谢! 最佳答案 通过using定义的类型名怎么样?templatestructTest{usingsomeType=decltype(T::foo());sta

c++ - 为什么 unique_ptr 不阻止自定义删除器的切片?

std::unique_ptr与自定义删除器的行为基于删除器的静态类型.没有多态性,没有基于运行时传递的实际删除器的运行时行为,因为提供的派生删除器被切片为声明的删除器的静态类型。(Itisdesignedthiswayinpurpose,toallowthesizeofunique_ptrwithdefaultdeleterorwithcustomdeleterwithoutanydatamembers,tohavesamesizeasarawpointer).带有自定义删除器的unique_ptr的静态行为:classA{};structBaseDeleter{virtualvoi

c++ - 帮助在 std::map 中存储模板类的 intrusive_ptr

我在boost::intrusive_ptr中包含一个Locker类型的小模板类,我想将其存储在std::map中:templateboolLockerManager::AddData(conststd::string&id,T*pData){boost::intrusive_ptr>lPtr(Locker(pData));//Line359-compilesmMap.insert(make_pair(id,lPtr));//Line361-giveserror}Locker只是一个容器类;它的构造函数看起来像:templateLocker::Locker(T*pData):Intru

c++ - 警告 : auto-importing has been activated without --enable-auto-import specified on the command line

我的环境:QtCreator2.3.1Qt4.7.4(32位)Windows7旗舰版(64位)尝试在QtforWindows中重建项目时,我遇到以下编译器警告:warning:auto-importinghasbeenactivatedwithout--enable-auto-importspecifiedonthecommandline.Thisshouldworkunlessitinvolvesconstantdatastructuresreferencingsymbolsfromauto-importedDLLs.发出此警告的项目包含一个DLL文件。尽管有警告,DLL中的类和函数

c++ - 为什么在单例实现中清除 boost::scoped_ptr

我使用boost::scoped_ptr实现了一个简单的单例:templateclassSingleton:publicboost::noncopyable{public:staticT&instance(){boost::call_once(init,flag);return*t;}staticvoidinit(){t.reset(newT());}private:staticboost::scoped_ptrt;staticboost::once_flagflag;};templateboost::scoped_ptrSingleton::t(0);templateboost::o

c++ - Boost Asio - 使用 shared_ptr 处理解析器和套接字

我有一个类能够通过TCP发送消息。这里是简化的界面:classCommandScreenshot:publicCameraCommand{public:CommandScreenshot();~CommandScreenshot();voidDispatch(boost::shared_ptrio_service);private:voidresolve_handler(constboost::system::error_code&err,boost::asio::ip::tcp::resolver::iteratorendpoint_iterator);};如您所见,我有一个函数Di