草庐IT

is_iterator

全部标签

c++ - 与 friend 一起上课而不是前向声明,: which compiler is correct

这个问题在这里已经有了答案:Friendmethod"notdeclaredinthisscope"inC++(1个回答)Error:'FriendMemberFunctionName'wasnotdeclaredinthisscope(3个答案)关闭3年前。我有这个简单的C++程序:#includestructobj{friendintf(int);voidm(intx){std::cout如果我使用GNUC++编译器g++进行编译,我会得到错误prog.cpp:7:55:error:'f'wasnotdeclaredinthisscope但是,如果我使用cl(和/W4)编译它,它会

c++ - 回复:使用 boost::make_transform_iterator 进行引用访问

我正在尝试使用boost::make_transform_iterator为自定义类创建迭代器,该自定义类的数据保存在映射中,迭代器使用键vector来访问值。在我的问题中,map的值是容纳大量数据的容器。由于我无力复制数据,因此我想通过迭代器通过引用访问数据。但是,这样做时,数据已损坏,如我所附的简单示例的输出所示。据我所知,问题在于使用from_key仿函数(使用映射引用初始化)和boost::make_transform_iterator的语义。关于如何使用boost正确执行此操作的任何想法?谢谢,帕特里克#include#include#include#include#incl

编译gcc踩坑记录——libtool: error: ‘/usr/local/lib/libgmp.la‘ is not a valid libtool archive

安装gcc依赖过程中出现错误,解决方法在google找到的。三个依赖如下:libgmplibmpfr依赖libgmplibmpc依赖libgmp、libmpfr直接就无脑(网上很多教程,这里就不赘述了)./configure--prefix=/home/xx/make&&makeinstall然后在libmpc时候就报错了:libtool:error:'/usr/local/lib/libgmp.la'isnotavalidlibtoolarchive解决方法:因为libmpc引用了libmpfr,libmpfr引用了libgmp而libgmp.la这个文件有bug,编译脚本里libtool路

c++ - 'auto' 关键字如何知道何时使用 const_iterator 匹配函数重载?

我了解thisquestion的内容但是当使用函数重载时,事情是如何工作的呢?例如在std::map中定义了以下方法:iteratorfind(constkey_type&k);const_iteratorfind(constkey_type&k)const;如何使用auto关键字来选择一个或另一个?以下内容对我来说似乎不正确:autoi=mymap.find(key);//callsthenon-constmethod?constautoi=mymap.find(key);//callstheconstmethod? 最佳答案 s

c++ - iterator_traits中的嵌套指针类型有什么用?

std::iterator_traits类模板定义了5个嵌套类型:iterator_category,value_type,difference_type,pointer和reference.浏览的来源libc++和libstdc++的头文件,可以看到value_type的许多用途,difference_type和iterator_category,但只有一个reference(在std::iter_swap内)并且pointer没有.我的应用程序使用手工构建的代理迭代器/代理引用对。我想过渡到使用Boostiterator_facade这让我可以从默认的T&配置引用类型到任意类型,但

c++ - SFINAE : Detecting if a function is called by a compile time known value

我喜欢在我的一个ctors以编译时已知值被调用时做一些检查。有办法检测吗?所以当有人调用它时:Aa(10);因为10是编译时已知常量,所以我喜欢调用一个特殊的构造函数,如下所示:template>A(intValue){}知道如何解决这个问题吗?谢谢! 最佳答案 积分常量可以解决您的问题:structA{template*=nullptr>A(std::integral_constant){}};然后,你可以像这样使用它:Aa{std:integral_constant{}};为了便于使用,您还可以使用类似于boost::hana的

c++ - is_assignable 和 std::unique_ptr

Here是来自gcc的测试文件,livedemostructdo_nothing{templatevoidoperator()(T*){}};intmain(){inti=0;std::unique_ptrp1(&i);std::unique_ptrp2;static_assert(!std::is_assignable::value,"");//note!here.}std::is_assignableIftheexpressionstd::declval()=std::declval()iswell-formedinunevaluatedcontext,providesthemem

c++ - Qt 信号/槽 : Is it an error to emit a signal from a temporary object?

在Qt中,如果从一个临时对象中调用一个信号,使得该对象可能在调用槽时被删除,这是一个错误吗?如果相关,代码会从临时对象的构造函数发出信号。(注意:没有指针或引用作为参数传递,所以这不是关于悬挂指针或引用的问题。我只是想知道,以最简单的形式,从Qt中的一个临时对象。)这是我的代码的简化版本://MyapplicationclassHandyApplication:publicQApplication{Q_OBJECTpublic:explicitHandyApplication(intargc,char*argv[]);signals:publicslots:voidhandySlot(

c++ - 调整自定义迭代器以便(a?)reverse_iterator 可以翻转它的输出

最近,用户@MooingDuck设计了concatenated_range,一个优雅的自定义迭代器,解决了“链接”两个迭代器的问题,一切都在幕后。它非常适合预期用途:autorange0=concatenate_ranges(x,x+i-1,x+i,x+a5+1);a6=foo(range0.first,range0.second);现在,我想通过执行(示例#2)来调整它:autorange0=concatenate_ranges(x+a5+1,x+i-1,x+i+1,x+n);a6=foo(std::reverse_iterator(range0.second),std::rever

c++ - 现代 C 和 C++ : it is possible to use one defined structure for other declared structure?

假设我想制作某种支持加载图形Image的引擎,所以我有structImage;Image*load_image_from_file(...);我不想让外部世界知道Image到底是什么,他们只会处理指向它的指针。但是在engine内部我想使用特定的类型,例如SDL_Surface在SDL中完全定义。我能否以某种方式重新定义此文件的图像,以便编译器在每次看到Image*(宏除外)时都假定为SDL_Surface*?即我想要像typedefstructSDL_SurfaceImage;这样的东西所有的尝试都像usingImage=SDL_Surface;typedefSDL_SurfaceI