草庐IT

move_disc

全部标签

c++ - P1236R1 : Why is the c++ standard trying to move away from the word "bit" when defining integers?

根据P1236R1,现在整数类型是用数字来定义的,不再是用位来定义的。typeminimumrangeexponentNsignedchar8short16int16long32longlong64C++没有定义标准仍然缺乏的“位”的含义,而是选择不这样做,而是在rangeexponent术语中定义这些类型。为什么?为什么不依赖“位”这个词比较好?该提案中的“不可观察位”是什么?P1236R1是partofC++20 最佳答案 根据ISO规则,ISOC++委员会的审议是私有(private)的,不能与整个编程社区共享。委员会已就此事

c++ - 从函数返回 const 对象会阻止从外部进行 move 构造吗?

给定这个函数和函数调用:std::stringGetString(){std::stringstreamsstr;constautostr=sstr.str();returnstr;}constautoreturnedStr=GetString();当我将str声明为const时会省略move构造吗? 最佳答案 在您的情况下,returnedStr将从GetString()的返回值move构造,但该返回值将从str复制构造(1)。如果str不是const,则返回值将从它move构造。注意,在这两种情况下,返回值优化仍然适用,因此编译

c++ - 从 r-value ref-qualified 方法 move 还是不 move ?

在以下C++11+代码中,应该首选哪个return语句构造?#includestructBar{};structFoo{Barbar;Barget()&&{returnstd::move(bar);//1returnbar;//2}}; 最佳答案 好吧,既然它是一个r-valueref限定的成员函数,this大概就要过期了。因此,将bar移出是有意义的,假设Bar实际上从被move中获得了一些东西。由于bar是一个成员,而不是本地对象/函数参数,因此在return语句中复制省略的常用标准不适用。除非您明确地std::move它,否则

c++ - 私有(private)构造函数禁止使用 emplace[_back]() 以避免 move

考虑以下代码:#includeclassA{public:A(A&&);//somewhatexpensivestaticstd::vectormake_As(){std::vectorresult;result.push_back(A(3));result.push_back(A(4));returnresult;}private:A(int);//privateconstructor};自从A的move构造函数有点昂贵(无论出于何种原因),我想避免调用它并使用emplace_back()而是:#includeclassA{public:A(A&&);//somewhatexpens

c++ - 我需要将 std::move 移植到我的内核吗?

我担心在内核领域我将无法访问std::move、std::forward、std::initializer_list之类的东西等。虽然其中一些功能内置在语言中,但它们仍然需要适当的header和库实现。以下内容是否足以利用移动语义,还是我需要走完整的九码并移植C++库?templatetypenameremove_reference::type&&move(T&&arg){returnstatic_cast::type&&>(arg);} 最佳答案 假设没有错别字,应该可以。标准中给出了完整的定义(实际上是两个;旧的和新的),我已经

c++ - 通用转换运算符模板和 move 语义 : any universal solution?

这是Explicitref-qualifiedconversionoperatortemplatesinaction的后续事件.我已经尝试了许多不同的选项,我在这里给出了一些结果,试图看看最终是否有任何解决方案。假设一个类(例如any)需要以一种方便、安全(毫无意外)的方式提供对任何可能类型的转换,同时保留move语义。我能想到四种不同的方法。structA{//explicitconversionoperators(nice,safe?)templateexplicitoperatorT&&()&&;templateexplicitoperatorT&()&;templateexpl

c++ - 如果成员具有非平凡的 noexcept 赋值运算符,则默认 move 赋值不能显式地为 noexcept

此代码使用gcc4.8.2(-std=c++11)编译失败,但使用clang3.4(trunk)(-std=c++11)编译:#include#includestructX{X&operator=(X&&)noexcept=default;//addingnoexceptthisleadstoanerroringcc,butworksinclang://function‘X&X::operator=(X&&)’defaultedonitsfirst//declarationwithanexception-specificationthatdiffersfromthe//implicit

c++ - 为什么要明确 move 转发引用?

我正在查看一些代码,我看到以下函数:templatestaticreturn_tmake_return(Args&&...args){//usingstd::forwardwillpreservelvalueargsassuch,butthepointofthisfunction//istomakeareturn,wherethe99.9+%caseismovingalocal(lvalue)intothereturnpack.//Thusitforcesamove,whichwillmove`T&`args(but_not_`constT&`args)intothe//returnp

c++ - 不可 move -不可复制对象的 vector 的 move 分配不编译

以下代码无法使用VisualStudio2013编译:#includestructX{X()=default;X(constX&)=delete;X&operator=(constX&)=delete;X(X&&)=delete;X&operator=(X&&)=delete;~X()=default;};voidfoo(){std::vectorv;std::vectorw;w=std::move(v);}错误信息说errorC2280:'X::X(X&&)':attemptingtoreferenceadeletedfunction这对我来说毫无意义。您应该不需要X的move构造函

c++ - move 分配和引用成员

对具有引用成员变量的类进行复制分配是禁忌,因为您无法重新分配引用。但是move分配呢?我尝试简单地move,但是当我只想move引用本身时,这当然会破坏源对象:classC{public:C(X&x):x_(x){}C(C&&other):x_(std::move(other.x_)){}C&operator=(C&&other){x_=std::move(other.x_);}private:X&x_;};Xy;Cc1(y);Xz;Cc2(z);c2=c1;//destroysyaswellasz我不应该只实现move分配并坚持move构造吗?这使得swap(C&,C&)难以实现。