草庐IT

boost-implicit-cast

全部标签

c++ - boost spirit qi 整数和 float 的数值解析

我正在尝试理解以下结果。测试用例代码为#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#includenamespacesp=boost::spirit;namespaceqi=boost::spirit::qi;usingnamespaceboost::spirit::ascii;namespacefusion=boost::fusion;namespacephoenix=boost::phoe

c++ - 使用 BOOST_FOREACH 时如何测试 vector 中的最后一个元素?

我有一个迭代vector。vector的最后一个元素是特例,我想单独测试一下。例如,我可能会这样做:for(iterator=vector.begin();iterator!=vector.end();++iterator){if((iterator+1)==(vector.end())){...}else{...}}我想用BOOST_FOREACH宏替换迭代器。是否可以对最终元素进行类似的测试? 最佳答案 if(!vec.empty()){BOOST_FOREACH(inte,boost::make_iterator_range(

c++ - const_cast 不适用于 C++?

这个问题在这里已经有了答案:Twodifferentvaluesatthesamememoryaddress(7个答案)关闭5年前。我有以下代码:constintk=1;int*p=const_cast(&k);cout(&k)=12;cout输出是:kbefore=1kafter=1为什么constcast在这里不起作用?

c++ - Qt 是否有与 Boost 的分配模块等效的东西?

在Boost中,有一些方便的函数可以让您在一行中填充一个容器。例如,list_of让你像这样填写一个列表。#include//for'list_of()'#includestd::listprimes=boost::assign::list_of(2)(3)(5)(7)(11);在我的项目中,我使用的是Qt,无法使用Boost。是否有类似方便的方法在构建时填充Qt的容器? 最佳答案 您可以使用QList::operatorQListprimes=QList() 关于c++-Qt是否有与B

c++ - 使用 Boost.MPI 库的目的是什么?

使用Boost.MPI库的目的是什么?它会boost性能吗?它和MPICH库有什么区别? 最佳答案 Boost.MPIprovidesanalternativeC++interfacetoMPIthatbettersupportsmodernC++developmentstyles,includingcompletesupportforuser-defineddatatypesandC++StandardLibrarytypes,arbitraryfunctionobjectsforcollectivealgorithms,andt

c++ - 如何编写自己的 dynamic_cast

这个在面试中被问到了。如何编写自己的dynamic_cast。我想,基于typeid的name函数。现在如何实现自己的typid?我对此一无所知。 最佳答案 你没有任何线索是有原因的,dynamic_cast和static_cast不像const_cast或reinterpret_cast,它们实际上执行指针运算并且在某种程度上是类型安全的。指针运算为了说明这一点,请考虑以下设计:structBase1{virtual~Base1();chara;};structBase2{virtual~Base2();charb;};struc

c++ - boost :什么是 "convenience header"?

boost中的“header”和“convenienceheader”有什么区别? 最佳答案 便利header通常(不仅仅是在Boost中)是一个包含许多其他header(包含实际代码)的header,这些header通常一起使用,即使它们之间没有硬依赖关系(这就是为什么它们'首先重新分开)。 关于c++-boost:什么是"convenienceheader"?,我们在StackOverflow上找到一个类似的问题: https://stackoverflo

c++ - 用于遍历继承层次结构的 Static_cast 与 dynamic_cast

我看到一本关于C++的书提到使用静态转换在继承层次结构中导航比使用动态转换更有效。例子:#include#includeusingnamespacestd;classShape{public:virtual~Shape(){};};classCircle:publicShape{};classSquare:publicShape{};classOther{};intmain(){Circlec;Shape*s=&c;//Upcast:normalandOK//Moreexplicitbutunnecessary:s=static_cast(&c);//(Sinceupcastingis

c++ - 将 Google Mock 与 boost::bind 结合使用

我有一个类,其构造函数采用Boost函数,我想使用GoogleMock对其进行测试。以下代码显示了一个示例类以及我对其进行测试的尝试:我的类.h:#includeclassMyClass{public:MyClass(boost::functioncallback);voidcallCallback();private:boost::functionm_callback;};MyClassTest.cpp:#include#include#include#include"MyClass.h"classCallbackMock{public:MOCK_METHOD0(callback,v

c++ - 复制 boost::shared_ptr

typedefboost::shared_ptrdata_ptr;data_ptrcached_ptr;//classmemberboolsomeWork(data_ptr&passed_ptr){//mustcopypassed_ptr=cached_ptrundersomeconditions//withoutpointingatthesamememory//IsawsomewherethatIshoulddo//passed_ptr.reset(newSomeData(???))//Idon'thavea"reset"onpassed_ptr}我查看了文档;复制和转换构造函数sh