草庐IT

boost-move

全部标签

c++ - 如何在获得 future 值(value)后重用 boost::promise 对象?

voidsss(boost::promise&res){res.set_value("hi");}voidyyy(boost::promise&res){res.set_value("hello");}intmain(){boost::threadth;boost::promisea;th=boost::thread(sss,boost::ref(a));th.join();std::cout我收到promise已经满足的错误。如何复用同一个Promise对象? 最佳答案 用未使用的promise替换它:a=boost::promi

c++ - 对 std/boost 移动的模糊调用

遇到无法编译的代码:#include#include#include#include#include#includeusingnamespacestd;intmain(){typedefstd::pair>FirstPair;typedefstd::vectorVectorFirstPair;typedefstd::pairSecondPair;typedefstd::mapMap;MapmapInstance;SecondPairnewElement=make_pair(boost::posix_time::not_a_date_time,VectorFirstPair());map

c++ - 是否可以从 std::string 中获取内存(就像 string move ctor 那样)?

如果我的内部类是我自己的vector版本(我控制来源)并且为了举例,我不能将其更改为std::string有没有办法从std::string窃取内存,就像std::string的move构造函数一样做。所以像这样:std::stringstr{"abcdefghijklmnopqrstu"};MyVectorCharClassmvc(std::move(str));//Constructortakesmemoryfromstr我想我听说过一些future的建议,以添加.release()至std::string或std::vector但我说的是现在。 最佳答

c++ - 从类中返回可 move 的成员变量

classfoo{public:barsteal_the_moveable_object();private:barmoveable_object;};main(){foof;automoved_object=f.steal_the_moveable_object();}如何实现steal_the_movebale_object将moveable_objectmove到moved_object中? 最佳答案 您可以直接在返回语句中简单地move成员:classfoo{public:barsteal_the_moveable_obje

c++ - move 使用无效?

有人能告诉我为什么这段代码没有输出任何东西吗?我假设它与move线有关...#include#include#includeusingnamespacestd;intmain(){vectorv{66,79,154,24,76,13,7};v=move(v);for(autoi:v)cout更新:所以我添加了system("pause");帮助自己。我是否需要它不是我关注的重点。当我在VisualStudio2013中再次运行代码时,它成功了。但是,当我使用C++14通过Ideone运行它时,它没有输出任何内容。现在有点困惑。 最佳答案

c++ - google test/mock vs boost vs catch 对 c++14/c++17 的支持

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。关闭5年前。Improvethisquestion我正在评估哪种测试框架最适合我。在这三个选项中选择:googletest、boost.test和catch。我想要一些健壮的东西,它没有那么多依赖性,并且能够在需要时支持C++14/C++17。还有一个问题,你知道航电/航天领域的大公司用的是什么框架吗?

c++ - 在破坏的对象上 move 构造函数?

我有一段代码#includeclassA{public:A(){std::cout我试着运行它,输出结果是DefaultconstructorDestructorMoveconstructorDestructor我的问题是为什么析构函数在move的构造函数之前被调用?这是否也意味着第二个对象是用销毁的值构造的? 最佳答案 从A&&f()返回局部变量与A&f()有同样的问题。它们都是引用。在main()中构造a时,局部变量已被销毁。这会导致引用已销毁的实例,从而导致未定义的行为。如果你想将A()从f()move到main中的a只需返回

c++ - 为什么有变异的 Boost.Range 算法的 const 重载?

Boost.Range的文档(和实现)显示了以常量引用作为参数的变异算法的重载。例如Boost.Range'sSortdocumentation显示:templateRandomAccessRange&sort(RandomAccessRange&rng);templateconstRandomAccessRange&sort(constRandomAccessRange&rng);templateRandomAccessRange&sort(RandomAccessRange&rng,BinaryPredicatepred);templateconstRandomAccessRang

c++ - Boost 1.65.1 几何距离策略使用 Visual Studio 2017 编译错误

尝试使用新版本的boost1.65.1编译我的项目时,出现以下错误:C:\Users\twozn\Dev\soundtoolkit\stk\libraries\boost/geometry/strategies/distance.hpp(101):errorC2664:'intboost::mpl::assertion_failed(boost::mpl::assert::type)':cannotconvertargument1from'boost::mpl::failed************(__cdeclboost::geometry::strategy::distance:

c++ - 在派生类到基类的转换中 move 语义

考虑以下类Buffer,它包含一个std::vector对象:#include#includeclassBuffer{std::vectorbuf_;protected:Buffer(std::byteval):buf_(1024,val){}};现在,考虑下面的函数make_zeroed_buffer()。BufferBuilder类是一个localclass公开派生自Buffer。它的目的是创建Buffer对象。Buffermake_zeroed_buffer(){structBufferBuilder:Buffer{BufferBuilder():Buffer(std::byte