草庐IT

compare_exchange_weak

全部标签

c++ - boost::python 和 weak_ptr:东西消失了

我想将对对象的引用存储为weak_ptr。在纯C++中,以下工作:#include#include#includeusingnamespacestd;usingnamespaceboost;structEmpty{Empty(){}};structStore{weak_ptrvalue;Store(){};voidsetValue(shared_ptrv){coutvalue=weak_ptr(v);shared_ptrv_ok=this->value.lock();if(v_ok){coutgetValue(){shared_ptrp=this->value.lock();if(p)

c++ - 从 weak_ptr 列表中删除项目

我有一个用于跟踪对象的weak_ptr列表。在某个时候,我想从给定shared_ptr或weak_ptr的列表中删除一个项目。#includeintmain(){typedefstd::list>intList;std::shared_ptrsp(newint(5));std::weak_ptrwp(sp);intListmyList;myList.push_back(sp);//myList.remove(sp);//myList.remove(wp);}但是,当我取消对以上行的注释时,程序将无法构建:1>c:\programfiles(x86)\microsoftvisualstu

c++ - 什么时候应该使用 std::atomic_compare_exchange_strong?

C++11中有两个原子CAS操作:atomic_compare_exchange_weak和atomic_compare_exchange_strong。根据cppreference:Theweakformsofthefunctionsareallowedtofailspuriously,thatis,actasif*obj!=*expectedeveniftheyareequal.Whenacompare-and-exchangeisinaloop,theweakversionwillyieldbetterperformanceonsomeplatforms.Whenaweakcom

c++ - 如果我碰巧注意到它已过期,我应该在 weak_ptr 上调用 reset 吗?

我收藏了Creature使用std::make_shared在我的应用程序的一部分中创建和拥有的对象和std::shared_ptr.我还跟踪了零个或一个的选择Creature在World使用std::weak_ptr的对象.voidWorld::SetSelection(conststd::shared_ptr&creature){selection=creature;}std::shared_ptrWorld::GetSelection()const{returnselection.lock();}GetSelection的来电者负责检查指针是否为空。如果是,则表示当前没有选择。T

c++ - 如果过期的 weak_ptr 会给出未定义的行为,那么 owner_less 有什么意义呢?

请顾及我的经验不足,不明白std::owner_less的意义.我已经shown那一个map与weak_ptr不推荐作为key,因为已过期weak_ptrkey会破坏map,实际上:Ifitexpires,thenthecontainer'sorderisbroken,andtryingtousethecontainerafterwardswillgiveundefinedbehaviour.这种行为有多不确定?我问的原因是因为docs说说owner_less:Thisfunctionobjectprovidesowner-based(asopposedtovalue-based)mi

c++ - 为什么 weak_ptr 可以打破循环引用?

我学到了很多关于weak_ptr与share_ptr一起使用来打破循环引用的知识。它是如何工作的?如何使用它?任何人都可以给我一个例子吗?我完全迷失在这里。还有一个问题,什么是强指针? 最佳答案 强指针持有对象的强引用——意思是:只要指针存在,对象就不会被销毁。对象不“知道”每个指针,只知道它们的编号——这就是强引用计数。weak_ptr会“记住”对象,但不会阻止它被销毁。你不能通过弱指针直接访问对象,但你可以尝试从弱指针创建一个强指针。如果该对象不再存在,则生成的强指针为空:shared_ptrsp(newint);weak_pt

c++ - 如何制作 std::weak_ptr 的 c++11 std::unordered_set

我有一个这样的集合:set,owner_less>>setName;它工作正常。但我想将其更改为无序集。但是,当我这样做时,我得到了大约六页错误。有什么想法吗?在查看所有页面的错误消息后,我找到了可能有帮助的行。/usr/include/c++/4.7/bits/functional_hash.h:60:7:error:staticassertionfailed:std::hashisnotspecializedforthistype/usr/include/c++/4.7/bits/stl_function.h:Ininstantiationof‘boolstd::equal_to:

c++ - 当 weak_ptr 的 shared_ptr 被销毁时会发生什么?

似乎是一个weak_ptr不知何故只知道什么时候shared_ptr它的引用已被销毁。那个怎么样?是否维护了一个恒定的链接或其他东西?取followingcodeforexample:weak_ptrtest(){shared_ptrfoo{newint};returnfoo;}intmain(){autofoo=test();cout当weak_ptr时,我预计会出现段错误去检查shared_ptr的状态但没有一个。weak_ptr正确地将内存识别为已释放。它怎么知道的? 最佳答案 Astd::shared_ptr使用两block

windows - git (ssh_exchange_identification) 连接由对等方重置(windows、gitlab)

我正在尝试在Windows(PuTTY)上使用ssh连接到gitlab服务器(我没有权限)。我尝试过的git客户端包括简单的git、git-extensions、sourcetree和gitbash/gui。他们基本上都告诉我:Cloninginto'repo'...debug2:ssh_connect:needpriv0debug1:Connectingtogit.server[x.y.z.w]port22.debug1:Connectionestablished.debug3:IncorrectRSA1identifierdebug3:Couldnotload"/c/Users/u

windows - 亚洲字符显示(带 Unicode): Difference in character spacing when presented in a RichEdit control compared with using ExtTextOut

这张图说明了我的困境:所有字符的大小看起来都一样,但与我使用ExtTextOut时相比,在RichEdit控件中显示时它们之间的间距不同。我想以与RichEdit控件中相同的方式显示字符(理想情况下),以保留换行位置。谁能告诉我:a)哪个表示更正确?b)为什么RichEdit控件显示的文本在亚洲字符之间没有间隙?c)有没有办法让ExtTextOut在绘制这些字符时重现RichEdit控件的行为?d)如果我使用的是亚洲版Windows,这会有什么不同吗?也许我很乐观,但如果有人能提供任何提示,我会很想听听。如果有帮助:这是我的文字:快的棕色狐狸跳在懶惰狗1234567890向亚洲读者道歉