草庐IT

type1Vector

全部标签

c++ - `mpl::plus< mpl::int_<1>, mpl::int_<2>>::type` 与 `mpl::int_<3>` 不是同一类型?

下面的代码再现了一个我真的不理解boostMPL库的行为:#include#include#includeusingnamespaceboost;intmain(){typedefmpl::int_one;typedefmpl::int_two;typedefmpl::int_three;//Thefollowinglinebreakscompilation...//static_assert(is_same::type,three>::type::value,"Notthesametype");//...whilethisworksstatic_assert(mpl::plus::t

c++ - 将 vector<shared_ptr<Derived>> 传递给需要 vector<shared_ptr<Base>> 的函数

我使用的代码结构有问题,如下(简化):classSPoint{public:SPoint(doublex,doubley,doublez):_x(x),_y(y),_z(z){}protected:double_x,_y,_z;}classPoint3D:publicSPoint{public:Point3D(doublex,doubley,doublez):SPoint(x,y,z){//defaultvaluesforUandV}protected:doubleU,V;}这些点用于创建折线:classSPolyline{public:SPolyline(constvector>&p

c++ - 排序和连接百万或十亿 STL vector 的最快方法

将数百万或数十亿个STLvector排序并串联成单个STLvector的最佳方法是什么。目前,我的做法是迭代vector并执行每个操作。这是伪代码typedefunsignedlonglongintULLInt;ULLIntN=1000000;vector>vecVec(N,vector());vectorconcatVec;//...//...fillvectorsinsidevecVechere//..wealsogetherethetotalnumberofvaluesinsertedinallvectors(count)//...//reservethespaceconcatV

c++ - vector 无效分配大小

当我尝试创建并调整一个vector以容纳最大数量的项目时(vector::max_size()),我在运行时遇到调试错误:"Invalidallocationsize:429467292"我想知道为什么你不能调整它的大小,如果max_size()应该返回vector中项目的最大数量......vectorvc;vc.resize(vc.max_size());我还尝试在VS2010中启用LARGADRESSAWARE:On,但这没有帮助。想知道这是否是正确的thoguth...有人知道吗? 最佳答案 max_size()是vecto

C++ 在 boost::mpl::vector 中为每个类加好友

如何在boost::mpl::vector中的每个类(class)都有一个类(class)friend?即,扩展为:templateclassA{friendclassmpl_vector[0];friendclassmpl_vector[1];...friendclassmpl_vector[n];}; 最佳答案 按照Andres的建议,使用boost预处理器进行处理。我试过了,不是很好,编译效率会很低。它也仅限于达到BOOST_MPL_LIMIT_VECTOR_SIZE。如果他的方法有效,那么它可能会更干净一些。A类.h:#if

c++ - 返回指向 const 对象的 const 共享指针的 const vector

给定以下基于共享指针容器的类,classFoo;classBar{public://...conststd::vector>&getFoos()const{returnfoos_;}private:std::vector>foos_;};不会编译因为invalidinitializationofreferenceoftype‘conststd::vector,std::allocator>>&’fromexpressionoftype‘conststd::vector,std::allocator>>’foos_成员需要指向可变的Foo对象供Bar对象内部使用,但我不想要客户端代码调用

c++ - 解码 Microsoft True Type 字体文件

我正在使用TFTLCD作为显示器(480x800px)的嵌入式平台(STM32F407)工作,并且想让我的用户界面在某种程度上为最终用户定制。我认为最好的字体来源是与Windows兼容的,因为它们最常见。我当前的实现使用我自己的二进制格式的自定义绘制字体和一个给出字符宽度和ascii值的描述符表,但不得不一点一点地绘制我自己的字体是乏味的。我想从SD卡中读取TrueType字体文件,并能够使用其中不同大小的字形,但我还没有看到关于如何实际实现这种魔力的直接实现。有人可以指出我正在寻找的一个很好的c/c++示例吗?作为解决问题的更好方法,我想制作一个简单的gcc命令行程序,它将使用“#”

c++ - 这是从 std::vector 中删除项目的有效方法吗?

这是我更新vector中项目列表并删除其中一些项目的代码:std::vectorparticles;...inti=0;while(iupdate();if(shouldRemove){deleteparticles[i];particles[i]=particles.back();particles.pop_back();}else{i++;}}当我找到应该删除的项目时,我将其替换为vector中的最后一项,以避免可能多次复制后备数组的其余部分。是的,我知道这是过早的优化......这是从vector中删除项目的有效方法吗?我偶尔会在这个区域附近的某个地方遇到一些(!)崩溃,但无法准

c++ - 在 C++ 中沿着二维 vector (塔防)移动

我正在写一个简单的塔防,我卡在了我的塔必须射击敌人的地方。使用这段代码:voidBullet::move(intx,inty,intspeed){Punktdelta={(x+speed)-this->x,(y+speed)-this->y};if(abs(delta.x)>1&&abs(delta.y)>1){this->x+=delta.x/this->speed;this->y+=delta.y/this->speed;}else{this->dead=true;}}其中方法参数是目标位置和速度。它应该沿着vector移动子弹直到它到达目标但是vector改变因为目标在移动。现在

c++ - cuda 上的 vector 步长加法较慢

我正在尝试在CUDAC++代码上运行vector步长加法函数,但对于大小为5,000,000的大型float组,它的运行速度也比我的CPU版本慢。以下是我正在谈论的相关CUDA和cpu代码:#defineTHREADS_PER_BLOCK1024typedeffloatreal;__global__voidvectorStepAddKernel2(real*x,real*y,real*z,realalpha,realbeta,intsize,intxstep,intystep,intzstep){inti=blockDim.x*blockIdx.x+threadIdx.x;if(i>>