草庐IT

boost-implicit-cast

全部标签

c++ - 具有不完整 Value 参数的 Boost.Iterator Facade

我正在尝试将boost::iterator_facade与不完整的Value一起使用模板参数。这失败了,因为iterator_facade正试图检查类型is_pod。这是预期的行为吗?我可以解决这个限制吗某种方式?我可以编写一个简单地代理foo和为它提供隐式转换,但我宁愿有一个更简单的解决方案。#includeclassiter:publicboost::iterator_facade{private:friendclassboost::iterator_core_access;voidincrement(){}boolequal(iterconst&other)const{retur

c++ - boost::bind 内部拷贝/拷贝?

我希望了解boost::bind执行何种函数对象的内部拷贝。由于这些对象的构造函数似乎没有被调用,我推测这是一种“非常浅的复制”,所以我引入了动态内存分配来产生一些错误。但是,下面代码的运行时输出似乎表明三个对bind生成的内部拷贝的额外析构函数调用。usingnamespacestd;usingnamespaceboost;classM{int*somedata;public:M(){somedata=newint[5];cout(instM,1)();//bind(&M::operator(),&instM,1)();//thisworkswithnoerrors,ofcourse

c++ - 如何重新分配 boost shared_ptr

我有两个Boostshared_ptrshared_ptrA(newX);shared_ptrB(newX);第三个指针最初指向与A相同的X。shared_ptrC=A;更改C使其指向与B相同的X的正确方法是什么?C=B; 最佳答案 EdChm是对的。我做了一个小测试程序来明确它。它使用C++11,但可以轻松转置。#include#includeintmain(){std::shared_ptrA(newint(1));//createsasharedpointerpointingtoanint.Soheunderlyinginti

c++ - 使用 Boost::Test 并行代码

我想用boost::unit_test为我的并行(基于mpi)C++代码创建一些测试。我对使用测试框架有一些基本的经验。对我来说,主要的问题是,在使用并行代码时,将MPI::Init放在哪里,以便首先调用它。在我创建的测试套件中没有主要功能。此外,当某些断言在现有等级的子集上失败时,Boost::Test是否正确存在(相对于mpi)? 最佳答案 Boost测试有fixturesupport,它允许您针对每个测试用例、测试套件或全局执行设置/清理。听起来您应该将对MPI::Init的调用放在全局固定装置中。structMPIFixtu

c++ - 在 VS2010 中使用 Boost.Pool - 链接器错误

Boost.Pooldocumentation说(强调我的):TheBoostPoollibraryisaheader-onlylibrary.Thatmeansthereisno.lib,.dll,or.sotobuild;justaddtheBoostdirectorytoyourcompiler'sincludefilepath,andyoushouldbegoodtogo!但是当我尝试在VS2010SP1中编译这样的代码时:#include#include#includeintmain(){typedefstd::basic_string,boost::pool_allocat

c++ - 如何使用 static_cast 安全地识别和释放这个 c++ 对象?

在其他Objective-C类中,我在下面的c++类中调用代码。有时fSound对象不是FMOD::Sound对象,它在被释放时会崩溃。在释放之前如何确认fSound对象是正确的类型?-(void)unloadSound:(FMOD::Sound*)fSound{FMOD_RESULTresult=FMOD_OK;FMOD::Sound*soundEffect=static_cast(fSound);if(soundEffect){soundEffect->release();}soundEffect=NULL;fSound=NULL;} 最佳答案

c++ - 在索引处分配 boost::mpl vector_c 元素的惯用方式

我有mpl::vector_c我想“分配”位置3的元素,比如说我想将它设置为30。因此,我必须写一个元函数获取和索引、vector和新值并返回修改后的序列。我最终得到了以下解决方案templateclassassign_element{typedeftypenamempl::begin::typebegin;typedeftypenamempl::advance>::typepos;typedeftypenamempl::erase::typesequence2;typedeftypenamempl::begin::typebegin2;typedeftypenamempl::adva

c++ - boost++::weighted_median 和 eigen::vectorXf --newbie

我想得到一个未排序的变量的加权中位数长度,Eigenc++vectorXf对象。看来我可以使用boost来自boost统计累加器的weighted_median函数库来有效地做到这一点[?]。本质上,我正在尝试做一些与已完成的非常相似的事情here.我不确定boost的累加器是正确的框架对于这个任务(如果不请建议!),但我还没有找到另一个O(n)加权中位数的现成实现。此时我的问题是是否有办法替换“for(inti=0;i附言我看过this所以问题,但事实并非如此真的很清楚如何将那里的答案变成可操作的解决方案。#include#include#include#include#includ

c++ - gcc 的 boost::variant 链接器错误

我有点发疯了,想弄清楚为什么以下代码无法编译:#include#include#include#includetypedefunsignedlonglongvery_long;typedefboost::variantvariants_type;typedefstd::arrayrow_type;typedefstd::forward_listrows_holder_type;intmain(){rows_holder_typerows;row_typerow_data;row_data[0]=0;row_data[1]=0;row_data[2]=0;row_data[3]=0;ro

c++ - boost图遍历显示 "hidden"节点

我开始尝试boost图类。为此,我创建了一个简单的示例,如下所示。当通过深度优先搜索算法遍历图形时,我没有添加一个节点。这是代码:#include#include#includetypedefboost::adjacency_listGraphType;typedefboost::graph_traits::vertex_descriptorVertexType;classVertexVisitor:publicboost::default_dfs_visitor{public:voiddiscover_vertex(VertexTypev,GraphTypeg){std::cout这