jjzjj

zero-copy

全部标签

c++ - 在 copy-and-swap 习语中实现交换

正在关注Whatisthecopyandswapidiom和Howtoprovideaswapfunctionformyclass,我尝试像后者接受的答案选项2那样实现交换函数(具有调用成员函数的自由函数),而不是前一个链接中的直接友好自由函数。但是下面的不编译#include//Uncommentingthefollowingtwolineswon'tchangethestateofaffairs//classBar;//voidswap(Bar&,Bar&);classBar{public:Bar(unsignedintbottles=0):bottles(bottles){enf

C++ 标准 : return by copy to initialize a reference without RVO: is there any copy?

让我们考虑下一个示例:structbig_type{};//Returnbycopyautofactory(){returnbig_type{};}voidany_scope_or_function(){big_type&&lifetime_extended=factory();}假设RVO被禁止或根本不以任何方式存在,big_type()是否会或可以被复制?还是将引用直接绑定(bind)到return语句中构造的临时对象?我想确保big_type析构函数仅在any_scope_or_function结束时被调用一次。我使用C++14,以防某些行为在标准版本之间发生变化。

c++ - 为什么这里调用的是 Copy Constructor 而不是普通的 Constructor 和重载的赋值运算符?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:IsthereadifferenceinC++betweencopyinitializationanddirectinitialization?CopyconstructorsandAssignmentOperators我有一个C类,我在其中重载了Normal、复制构造函数和赋值运算符以打印被调用内容的踪迹。我写了以下代码来测试什么时候被调用?Cc1;-->NormalConstuctor..//understoodFineCc2;c2=c1;-->Normalconstructor+assignmentop

c++ - copy-and-swap 技术在赋值运算符函数中使用复制构造函数

我正在阅读“EffectiveC++byScottMeyers”,其中第11项建议在我的赋值运算符中使用“copy-and-swap”技术:Widget&Widget::operator=(constWidget&rhs){Widgettemp(rhs);//Copyconstructorswap(temp);//Swapwith*thisreturn*this;}但是在Item12中是这样写的:Itmakesnosensetohavecopyassignmentoperatorcallthecopyconstructor.我认为第11项和第12项是矛盾的。我理解错了吗?

c# - 无法在我的 WPF 应用程序中使用 Array.Copy()

我是一名C++开发人员,最近开始从事WPF方面的工作。好吧,我在我的应用程序中使用Array.Copy(),看起来我无法完全获得所需的结果。我在我的C++应用程序中做了如下操作:staticconstsignedcharversion[40]={'A','U','D','I','E','N','C','E',//name0,0,0,0,0,0,0,0,//reserved,firmwaresize0,0,0,0,0,0,0,0,//boardnumber0,0,0,0,0,0,0,0,//variant,version,serial0,0,0,0,0,0,0,0//datecode,r

Zero-shot RIS SOTA:Text Augmented Spatial-aware Zero-shot Referring Image Segmentation 论文阅读笔记

Zero-shotRISSOTA:TextAugmentedSpatial-awareZero-shotReferringImageSegmentation论文阅读笔记一、Abstract二、引言三、相关工作3.1Zero-shot分割3.2ReferringImageSegmentation3.3ImageCaptioning四、方法4.1总体框架4.2MaskProposal网络FreeSOLOvs.SAM4.3文本增强的视觉-文本匹配得分V-scoreP-scoreN-scoreThetext-augmentedvisual-textmatchingscore4.4空间校正器方向描述鉴定

c++ - 对于具有抛出复制构造函数和 noexcept 按值复制赋值的类,is_nothrow_copy_assignable 的值是多少?

根据C++标准,以下程序的预期(如果有)输出是什么:#include#include#includeclassA{public:A()=default;~A()=default;A(Aconst&other){}A(A&&other)noexcept{}A&operator=(Aother)noexcept{return*this;}};intmain(){std::cout::value::value换句话说,类型特征值的评估是否只看赋值运算符的声明,即noexcept,并因此产生truetrue或者它是否考虑调用上下文(a、b是A的实例)a=b;//maythrow,implici

c++ - 错误 : copy assignment operator not allowed in union

当出现以下错误时,我正在编译下面的代码。我找不到原因。typedefunion{struct{constintj;}tag;}X;intmain(){return0;}error:member`::``::tagwithcopyassignmentoperatornotallowedinunion虽然这段代码使用gcc编译罚款。仅使用g++时出错。 最佳答案 为了拥有某个类类型T的union成员,T的特殊成员函数(默认构造函数、复制构造函数、复制赋值运算符、和析构函数)必须是微不足道的。也就是说,它们必须是由编译器隐式声明和定义的。

c++ - 为什么memcpy复制Eigen矩阵数据失败,std::copy成功?

当我使用Eigen创建矩阵时,如下所示:Eigen::MatrixXdM(3,3);M产生147258369我可以用指针遍历数据,打印每个元素:double*d=M.data();for(inti=0;i产生123456789我还可以使用std::copy将其复制到堆栈上相同类型的数组,然后打印该数组的元素:doubledata_copy[9];std::copy(M.data(),M.data()+M.size(),data_copy);for(inti=0;i产生123456789但是,我似乎无法使用memcpy进行等效复制。这只能复制第一个元素:doubledata_memcop

c++ - 在基类和派生类中 copy-and-swap

我最近读到copy&swap现在我正在尝试在基类和派生类中实现ctors。我的基类和派生类中都有四个构造函数,但是我不确定如何实现派生类的赋值运算符。explicitBase(inti):m_i{i}{}Base(constBase&other):m_i{other.m_i}Base(Base&&other):Base(0){swap(*this,other);}Base&operator=(Baseother){swap(*this,other);return*this;}friendvoidswap(Base&a,Base&b)noexcept{usingstd::swap;swa