草庐IT

self-assignment

全部标签

c++ - 从 enable_shared_from_this 返回 self 的 shared_ptr 继承的类的子类

我想知道是否有像这样的伪代码来做一些事情:classA:publicstd::enable_shared_from_this{public:std::shared_ptrgetPtr(){returnstd::static_pointer_cast(shared_from_this());}};classB:publicA{std::vectorcontainer;std::shared_ptraddChild(Achild){container.push_back(child);returngetPtr();}};classC:publicB{public:std::shared_p

c++ - 在 MoveAssignable 的情况下,标准对 self 移动赋值有何看法?

这是C++17的currentdescriptionMoveAssignable的:t=rv;Iftandrvdonotrefertothesameobject,tisequivalenttothevalueofrvbeforetheassignmentrv'sstateisunspecified.[ Note:rvmuststillmeettherequirementsofthelibrarycomponentthatisusingit,whetherornottandrvrefertothesameobject.Theoperationslistedinthoserequireme

【多模态(影像)自监督学习】Uni4Eye: Unified 2D and 3D Self-supervisedPre-training via Masked Image ModelingTran

Abstract大规模标记数据集是计算机视觉中监督深度学习成功的关键因素。然而,标注的数据数量有限是非常常见的,特别是在眼科图像分析中,因为手动标注是费时费力的。自监督学习(SSL)方法为更好地利用未标记数据带来了巨大的机会,因为它们不需要大量的注释。为了尽可能多地使用未标记的眼科图像,有必要打破尺寸障碍,同时使用2D和3D图像。在本文中,我们提出了一个通用的自监督Transformer框架,名为Uni4Eye,用于发现眼科图像的固有属性并捕获嵌入的特定领域特征。Uni4Eye可以作为一个全局特征提取器,它建立在一个具有视觉转换(ViT)架构的蒙面图像建模任务的基础上。我们采用统一的Patch

c++ - 如何解释 is_assignable 中的 declval<_Dest>() = declval<_Src>()

我想弄清楚如何在is_assignable的实现中解释declval()=declval()。declval将类型转换为引用。鉴于此,我将表达式转换为以下四种可能性之一:_Dest&&=_Src&&_Dest&&=_Src&_Dest&=_Src&&_Dest&=_Src&然后我创建了两个辅助函数。templateTrvalue();templateT&lvalue();我的理解是这四个表达式可以用模板函数实现。_Dest&&=_Src&&----->右值()=右值()其他三个也是一样。然后我通过编译三对具体类型的每种可能性的模板函数版本来模拟decltype(declval()=de

c++ - std::vector::assign - 重新分配数据?

我正在使用STL库,我的目标是尽量减少数据重新分配的情况。我在想,是吗?std::vector::assign(size_typen,constvalue_type&val)如果大小未更改或实际上只是分配新值(例如,使用operator=),则重新分配数据?STL文档位于http://www.cplusplus.com/说以下(C++98):Inthefillversion(2),thenewcontentsarenelements,eachinitializedtoacopyofval.Ifareallocationhappens,thestorageneededisallocate

c++ - std::string not nothrow move assignable or comparable?

我在研究type_traits时,发现了std::string的这个奇怪属性:$cata.cpp#include#includestatic_assert(std::is_nothrow_move_assignable::value,"???");static_assert(noexcept(std::declval()==std::declval()),"???");$g++-std=c++14a.cppa.cpp:4:1:error:staticassertionfailed:???static_assert(std::is_nothrow_move_assignable::val

c++ - lambda 函数不是 throw_move_assignable 吗?

clang-cl(4.0.0-trunk)似乎认为是,而vc2015(update3)认为不是。此实现是否已定义或标准是否规定了lambda函数应如何在术语或nothrow和moveassignable中实现?#include#includetemplatevoidtest_nothrow_move_assignable(T&&){std::cout::value 最佳答案 这是clang错误。来自[expr.prim.lambda]:Theclosuretypeassociatedwithalambda-expressionhas

c++ - msvc is_copy_assignable 始终为真?

#includeclassTest{public:Test(constTest&)=delete;Test&operator=(constTest&)=delete;};voidfn(Test&a,constTest&b){a=b;}static_assert(!std::is_copy_assignable::value,"Testshouldn'tbeassignable");在MSVC2013Update3下编译此代码时static_assert意外失败,并且函数fn编译失败(如预期)。这很矛盾,对吧?我是否滥用了is_copy_assignable?有没有其他方法可以测试这种情

c++ - copy-and-swap 习语在 self 分配期间如何工作?

我正在阅读优秀的copy-and-swapidiom问题和答案。但是我没有得到一件事:在self分配的情况下它是如何工作的?例子中提到的对象other不会释放分配给mArray的内存吗?那么,自分配的对象不会以拥有无效指针而告终吗? 最佳答案 ButonethingIamnotgettinghowdoesitworkincaseofselfassignment?让我们看一个简单的例子:classContainer{int*mArray;};//CopyandswapContainer&operator=(Containerconst

c++ - 为什么我得到一个 Expression is not assignable 错误

我不明白为什么我从以下代码中收到“表达式不可分配”错误:classvalue_t{public:inta;};classvalues_t{public:std::maplist;value_t*operator[](conststd::string&key){returnlist[key];}value_t*get(conststd::string&key){returnlist[key];}};intmain(intargc,constchar*argv[]){values_tvalues;values.list["aaa"]=newvalue_t();//OKvalues["aaa