草庐IT

boost-move

全部标签

c++ - 使用 boost.python 公开 std::vector<double>

我已经编写了一些生成std​​::vector的C++代码。我还有一个python脚本来处理一些数据,目前,我是这样声明的(如下)。importnumpyx=numpy.random.randn(1000)y=numpy.random.randn(1000)我可以很好地运行脚本。来self的C++代码:usingnamespaceboost::python;try{Py_Initialize();objectmain=import("__main__");objectglobal(main.attr("__dict__"));objectresult=exec_file("scatte

c++ - 执行简单的 boost 线程程序时出错

你能告诉mw下面的boost::thread程序有什么问题吗#include#includeboost::mutexmutex;classA{public:A():a(0){}voidoperator()(){boost::mutex::scoped_locklock(mutex);}private:inta;};intmain(){boost::threadthr1(A());boost::threadthr2(A());thr1.join();thr2.join();我收到错误信息:错误:请求'thr1'中的成员'join',它是非类类型'boost::thread()(A()()

c++ - 我如何将 Qt 的 QVariant 转换为 boost::any?

如何将Qt的QVariant转换为boost::any? 最佳答案 我认为没有简单的方法,我会做以下事情:boost::anyqvariant_to_any(constQVariant&v){switch(v.userType()){caseQVariant::Bool:returnboost::any(v.value());//or:returnboost::any(v.toBool());caseQVariant::Int:returnboost::any(v.value());//or:returnboost::any(v.t

C++ Linux : error: ‘move’ is not a member of ‘std’ how to get around it?

所以在我的VS2010上我可以编译如下代码:boost::shared_ptrinternal_thread;boost::packaged_taskinternal_task_w(boost::bind(&thread_pool::internal_run,this,internal_thread));internal_thread=boost::shared_ptr(newboost::thread(std::move(internal_task_w)));前两行在boost1.47.0和linux上没问题...但是在std::move上它给出了error:‘move’isnota

c++ - N Boost interval_set 的组合

我的一项服务在4个不同的位置出现中断。我正在将每个位置的中断建模到一个BoostICLinterval_set中。我想知道至少N个位置何时发生事件中断。因此,关注thisanswer,我已经实现了组合算法,因此我可以通过interval_set交集在元素之间创建组合。当这个过程结束时,我应该有一定数量的interval_set,它们中的每一个同时定义N个位置的中断,最后一步将加入它们以获得所需的全貌。问题是我目前正在调试代码,当打印每个交叉点的时间到了时,输出的文本变得疯狂(即使我正在使用gdb逐步调试),我无法看到它们,导致大量的CPU使用率。我想我以某种方式发送输出的内存比我应该的

c++ - 为什么 boost.geometry.index.rtree 比 superliminal.RTree 慢

我测试了boost.geometry.index.rtree(boost1.59www.boost.org)和superliminal.RTree(http://superliminal.com/sources/sources.htm#C_Code)。令我惊讶的是,superliminal.RTree比boost.geometry.index.rtree更快。环境设置将相同的空间索引数据添加到superliminal.RTree和boost.geometry.index.rtree对象。测试相同的空间索引查询100次并获得消耗的时间。GCC版本是“gccversion4.4.62011

c++ - 为什么需要 move 语义来消除临时拷贝?

所以我对move语义的理解是,它们允许您覆盖用于临时值(右值)的函数,并避免可能昂贵的拷贝(通过将状态从未命名的临时值move到您命名的左值)。我的问题是为什么我们需要特殊的语义?为什么C++98编译器不能省略这些拷贝,因为是编译器决定给定表达式是左值还是右值?例如:voidfunc(conststd::string&s){//Dosomethingwiths}intmain(){func(std::string("abc")+std::string("def"));}即使没有C++11的move语义,编译器仍然应该能够确定传递给func()的表达式是右值,因此不需要从临时对象进行复制

c++ - 与 move 构造函数混淆 : unable to call move constructor

我一直难以理解C++中的move构造函数。我用默认构造函数、复制构造函数、move构造函数和析构函数制作了一个简单的类。此外,我定义了一个具有两个重载的函数,一个接受对该类的引用,一个接受对该类的右值引用。我的测试代码如下。#includeclassc{public:c(){std::cout我得到的输出不是我所期望的。以下是我从此代码获得的输出。defaultconstructorcopyconstructorpassedbyreferencedefaultconstructorpassedbyrvaluereferencedestructor除了第3行,我能理解所有行的输出。在第3

c++ - Visual Studio 2010 中 std::make_shared() 的友元函数(不是 Boost)

如何创建std::make_shared()的友元函数。我试过:classMyClass{public:friendstd::shared_ptrstd::make_shared();//or//friendstd::shared_ptrstd::make_shared();protected:MyClass();};但它不起作用(我使用的是VisualStudio2010SP1) 最佳答案 如何向您的类添加一个静态方法:classFoo{public:staticshared_ptrcreate(){returnstd::shar

c++ - std::move 的类型是什么?

此代码按预期工作(在线here)。最后v是空的w不是空的,因为它窃取了v的内容.vectorv;v.push_back(1);coutw(vp);cout但是如果我替换autovp=move(v)与vector&&vp=move(v);然后它就不动了。相反,它复制并且两个vector最后都是非空的。如图here.说明:更具体地说,vp的自动派生类型是什么??如果不是vector&&,那还能是什么呢?尽管这两个示例如此相似,但为什么会给出不同的结果?Extra:这个我也试过了,还是复制而不是movestd::remove_reference>::type&&vp=move(v);