草庐IT

std-ranges

全部标签

c++ - std::string 内存泄漏

我有这个类AppController和函数connectPlayer:/*AppController.h*/classAppController{//Someotherdeclarations...private:staticconststringTAG;};/*AppController.cpp*/#include"AppController.h"conststringAppController::TAG="AppController";AppController::AppController(){/*somecodehere...*/}voidAppController::conn

C++ std::sort() 调用析构函数

我重载了我的类的()运算符以将其用作排序比较器函数。使用std::sort()时,出于某种原因,它多次调用类的析构函数(显然取决于vector中的条目数量)。我在~RANK()中描述了更多内容。#include#include#include#includeclassRANK{structCOMBO{intx;};std::vectordata;public:RANK(){printf("RANK()\n");}~RANK(){printf("~RANK()\n");/**Hereistheproblem.*SincemyvectorconsistsofpointerstoCOMBOo

c++ - 为什么这个程序抛出 'std::system_error' ?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whydoesthissimplestd::threadexamplenotwork?代码:#include#includevoidf(){std::cout问题:$g++-othread_testthread_test.cpp-std=c++0x$./thread_testterminatecalledafterthrowinganinstanceof'std::system_error'what():OperationnotpermittedAbortado“Abortado”在我的语言环境中表示“中止”

c++ - 使用 std::vector.erase(begin(), end()) 或 std::vector.erase(begin(), begin()) 安全吗?

我想处理vector中的元素一段时间。为了优化这一点,我不想在处理项目时删除它,而是在最后删除所有已处理的项目。vector::iteratorit;for(it=items.begin();it!=items.end();++it){DoSomething(*it);if(TimeIsUp()){break;}}items.erase(items.begin(),it);当it==items.end()时使用erase是否安全?在文档中说erase()将删除[first,last)并且这应该是安全的,但我想确定。编辑:使用std::vector.erase(begin(),begin

c++ - Visual Studio 监 window 口如何知道展开 `std::vector<T>` 并显示元素?

如果你展开std::vector在监window口中,您将获得诸如“[0]”、“[1]”等项,集合中的每个值对应一项。在实现我自己的集合类时(顺便说一下,它包装了一个动态数组),我想要同样的功能。VisualStudio如何知道要在std::vector的监window口中显示多少元素?? 最佳答案 有一个名为autoexp.dat的文件,调试器使用它来解释自定义类型。它并不正式意味着要进行编辑,但我们已经在内部将其用于集合类型并且它工作正常。有一些粗糙的边缘。http://msdn.microsoft.com/en-us/libr

c++ - C++ std::numeric_limits<float>::max() 能否准确地存储在一个 float 中,然后进行比较?

我知道有些值无法在float中轻松定义,并且只是“近似值”,因此直接“等于”比较通常不起作用。std::numeric_limits::max能否准确地存储在float中,这段代码能否按预期运行?floatmyFloat=std::numeric_limits::max();//...later...if(myFloat==std::numeric_limits::max()){//...myFloathasn'tchanged...} 最佳答案 对于给定的(非NaN)float变量,f,保证f==f总是正确的。自myFloat设置

c++ - GLSL布局std140填充困境

我有以下统一缓冲区:layout(std140)uniformLight{vec4AmbientLight;vec4LightIntensity;vec3LightPosition;floatLightAttenuation;};我在缓冲数据和需要添加的填充时遇到了一些问题。我读过http://ptgmedia.pearsoncmg.com/images/9780321552624/downloads/0321552628_AppL.pdf这表示我必须在vec3的末尾添加额外的4个字节用于填充-因此我将为“Light”上传总共13个字节。然而,当我这样做时,'LightAttenuat

c++ - 使用 std::for_each lambda 函数时出错

我有一个小问题,我不明白为什么这段代码不起作用:std::for_each(users.begin(),users.end(),[](Wt::WStringu){std::coutaddItem(u);});编译时遇到的错误:GameWidget.cpp:Inlambdafunction:GameWidget.cpp:352:30:error:'users'isnotcapturedGameWidget.cpp:353:4:error:'this'wasnotcapturedforthislambdafunctionGameWidget.cpp:Inmemberfunction'vir

c++ - 如果存在仅推送线程和仅弹出线程,C++ std::queue 是否安全?

我想知道这种情况是否(线程)安全。有一个线程只推送到一个std::queue。还有另一个线程只从std::queue弹出。由于队列是否为空,线程安全地管理,后面的线程不会弹出失败。你能帮帮我吗?谢谢。 最佳答案 我认为答案是否定的。标准说(§23.2.2/1):Forpurposesofavoidingdataraces(17.6.5.9),implementationsshallconsiderthefollowingfunctionstobeconst:begin,end,rbegin,rend,front,back,data,

c++ - 在 C++ 中使用 std::forward

我遇到过一段代码,其中使用了std::forward。我在谷歌上搜索了很长时间,但无法理解它的真正目的和用途。我在stackoverflow上看到过类似的帖子,但还是不太清楚。有人可以用一个简单的例子来解释吗?PS:我已经经历过这个page,但仍然无法欣赏它的用途。请不要将此问题标记为重复,而是尝试帮助我。 最佳答案 如您链接的页面所示:Thisisahelperfunctiontoallowperfectforwardingofargumentstakenasrvaluereferencestodeducedtypes,prese