草庐IT

imap_mail_move

全部标签

c++ - 为什么 move on const 对象有效?

我有一个简单的代码:conststd::vectordata={1,2,3};std::vectordata_moved=std::move(data);for(auto&i:data)cout编译没有任何错误或警告!!并且data中似乎仍有值!moveconst值似乎不正确,因为我们无法修改const对象那么该代码如何编译?! 最佳答案 您没有move任何东西。std::move名字真的很糟糕:它不会强制move;它只是返回一个右值。std::vector的构造函数由编译器决定。调用,而这决定了您是否会采取行动。如果由于目标的mo

c++ - move 的对象仍然被破坏?

在学习C++11时,我对move对象的行为方式感到惊讶。考虑这段代码:#include#include#includeclassMoveable{public:Moveable(){std::cout::value,"isnotcopyconstructible");static_assert(!std::is_copy_assignable::value,"isnotcopyassignable");static_assert(std::is_move_constructible::value,"ismoveconstructible");static_assert(std::is_

c++ - 返回 const 值以利用 move 语义与防止诸如 (a+b)=c 之类的东西

这个问题在这里已经有了答案:Isn'ttheconstmodifierhereunnecessary?[duplicate](5个答案)关闭8年前。我认为thisquestion有点被误解了。返回const值并不是可以被视为无意义的东西。正如AdamBurry在评论中指出的那样,ScottMeyers在更有效的C++(第6项)中推荐了它,我将向其中添加HerbSutter的ExceptionalC++(第20项,类力学,其对应的GotW为availableonline)。这样做的基本原理是您希望编译器捕获像(a+b)=c(哎呀,意思是==)这样的拼写错误,或误导性语句像a++++,这两

c++ - std::move 与 std::make_pair

有什么区别:std::map>m;Tt1,t2;m.emplace(1,std::make_pair(t1,t2));和:std::map>m;Tt1,t2;m.emplace(1,std::move(std::make_pair(t1,t2)));std::move在这里是多余的吗?std::map::emplace和perfectforwarding是否负责直接在std::中分配std::pairmap? 最佳答案 std::make_pair(...)和std::move(std::make_pair(...))都是右值表达式

c++ - 为什么 std::vector 使用 move 构造函数,尽管声明为 noexcept(false)

无论我在互联网上的什么地方阅读,强烈建议如果我希望我的类(class)与std::vector一起工作(即std使用我类(class)的move语义::vector)我应该将构造函数delcaremove为'noexcept'(或noexcept(true))。为什么std::vector使用它,即使我将它标记为noexcept(false)作为实验?#include#includeusingstd::cout;structT{T(){coutt_vec;t_vec.push_back(T());}输出:T()T(T&&)~T()~T()为什么?我做错了什么?在gcc4.8.2上编译,

c++ - 你能重用 move 的 std::string 吗?

这个问题在这里已经有了答案:Reusingamovedcontainer?(3个答案)关闭8年前。给出这个例子:std::vectorsplit(conststd::string&str){std::vectorresult;std::stringcurr;for(autoc:str){if(c==DELIMITER){result.push_back(std::move(curr));//ATTENTIONHERE!}else{curr.push_back(c);}}result.push_back(std::move(curr));returnresult;}我可以重用currst

imap-send.c:865:错误:“ HAMC”的存储大小未知

将GIT安装在CentOS版本6.9(最终)中。当我制作异常时,它停止了看答案您要编译的软件与系统上可用的OPENSL版本不兼容。您的系统正在提供最新版本的OpenSSL(1.1.0),但是您正在编译的软件期望它的较早版本(可能1.0.2)。OpenSSL1.1.0与1.0.2的源不完全兼容。除了提供的系统版本外,您还需要提供OpenSSL1.0.2版本,并确保您的软件在编译过程中使用。

c++ - std::move 是否使指针无效?

假设如下:templateclassPipeline{[...]voidconnect(OutputSidefirst,InputSidesecond){Queuequeue;first.setOutputQueue(&queue);second.setInputQueue(&queue);queues.push_back(std::move(queue));}[...]std::vector>queues;};move后指向队列的指针在“first”和“second”中是否仍然有效? 最佳答案 Doesstd::moveinval

c++ - valgrind Conditional jump or move depends on uninitialised value(s) ,这是否表示内存泄漏?

我在代码中遇到内存泄漏问题,在它运行时,堆不断增加到最大值,我需要重新启动服务,我运行了top命令,看到每当我调用一个场景时堆都在增加服务。我用valgrind运行服务,valgrind--log-file=log-feb19.txt--leak-check=full--show-reachable=yes--track-origins=yesmyservice我在运行场景时没有看到任何明显丢失或可能丢失的block,但我看到很多条件跳转或移动取决于未初始化的值错误。这些是否算作内存泄漏?我得到的例子:==27278==Conditionaljumpormovedependsonuni

c++ - 将对象作为函数参数发送时 move 语义

我在玩move构造函数和move赋值时偶然发现了这个问题。第一段代码:#include#includeclassFoo{public:Foo(){}Foo(Foo&&other){value=std::move(other.value);other.value=1;//sinceit'sint!}intvalue;private:Foo(constFoo&other);};voidBar(Foo&&x){std::cout在我看来,当我使用:Bar(std::move(foo));程序应将foo对象“move”到使用Bar函数中的move构造函数创建的临时对象。这样做会使foo对象的值