草庐IT

c++ - GCC 的 <experimental/ranges> 过滤器 View 无法使用无限范围 iota() 进行编译

我正在探索gcc中的实验范围库实现。将无限iota范围与过滤器View组合时,我得到了一个令人惊讶的编译错误(liveexample与GCC9.0HEAD201812):#include#include#includeintmain(){usingnamespacestd::experimental::ranges;autoodds=view::filter([](intx){returnx%2!=0;});//autov=std::vector{0,1,2,3,4,5};//autox=v|odds;//(1)ok//autox=view::iota(0,6)|odds;//(2)o

c++14 static constexpr auto 与 odr 用法

我有以下C++14代码:templatestructTest{staticconstexprautosomething{T::foo()};};这很好,只要T::foo()也是一个constexpr。现在我知道something是ODR使用的,所以我需要提供命名空间声明。我应该使用什么语法?templateconstexprautoTest::something;不起作用。谢谢! 最佳答案 通过using定义的类型名怎么样?templatestructTest{usingsomeType=decltype(T::foo());sta

c++ - 影响自动类型推导

假设我正在编写一个返回某种代理对象的函数,比如说用于惰性求值或其他目的。如果我写这样的代码autox=func();然后x将是返回值的类型-不是我想要代理的对象的类型。是否可以更改auto或decltype以便在这种情况下使用它们将返回我想要返回的实际结果,而不是代理对象本身的类型? 最佳答案 随意的想法:您可以使用decltype(*func())获取代理对象的类型,或者访问代理对象。除了通常的const、&等,auto没有修饰符。如果它是惰性求值,您现在可能不想要最终对象类型,对吗?如果代理对最终对象有一个转换运算符,auto怎

c++ - 警告 : auto-importing has been activated without --enable-auto-import specified on the command line

我的环境:QtCreator2.3.1Qt4.7.4(32位)Windows7旗舰版(64位)尝试在QtforWindows中重建项目时,我遇到以下编译器警告:warning:auto-importinghasbeenactivatedwithout--enable-auto-importspecifiedonthecommandline.Thisshouldworkunlessitinvolvesconstantdatastructuresreferencingsymbolsfromauto-importedDLLs.发出此警告的项目包含一个DLL文件。尽管有警告,DLL中的类和函数

c++ - 试图理解 auto_ptr

我试图了解有关auto_ptr类如何工作的某些细节。假设您有以下类(class)(我是在一个网站上找到的,该网站上有人解释了赋值运算符的要点)。classTFoo:publicTSuperFoo{auto_ptrfBar1;auto_ptrfBar2;public:TFoo&TFoo::operator=(constTFoo&that);//variousothermethoddefinitionsgohere...}现在是赋值运算符的实现。TFoo&TFoo::operator=(constTFoo&that){if(this!=&that){auto_ptrbar1=newTBar

c++ - 为什么不能形成对 'decltype(auto)' 的引用

intmain(){decltype(auto)&&a=100;}以上代码,在GCC和Clang中出错。intmain(){decltype(int)&&a=100;}此代码正确。在N4296中,在§8.3.2/6Ifatypedef(7.1.3),atypetemplate-parameter(14.3.1),oradecltype-specifier(7.1.6.2)denotesatypeTRthatisareferencetoatypeT,anattempttocreatethetype“lvaluereferencetocvTR”createsthetype“lvaluere

python - Cython 扩展类 : How do I expose methods in the auto-generated C struct?

我现有的C++代码定义了一些我需要使用的类,但我需要能够将这些类发送到Python代码。具体来说,我需要在C++中创建类实例,创建Python对象作为这些C++对象的包装器,然后将这些Python对象传递给Python代码进行处理。这只是一个更大的C++程序的一部分,因此最终需要使用C/PythonAPI在C++中完成。为了让我的生活更轻松,我使用Cython定义扩展类(cdef类)作为我的C++对象的Python包装器。我使用的是典型格式,其中cdef类包含指向C++类的指针,然后在创建cdef类实例时对其进行初始化。因为如果我有一个现有的C++对象要包装,我也希望能够替换指针,所以

c++ - 有没有办法在编译时检测是否可以使用给定的一组参数类型成功调用通用 lambda?

我希望能够在编译时确定,给定一个通用的lambda类型,它是否可以用一组给定的参数类型调用。我有以下示例C++14实现:#include//helperfunction;thisoverloadhandlesthecasethatthecallispossible//useSFINAEwiththeextratemplateparametertoremovethisfromconsiderationwhenthe//callisill-formedtemplate()(std::declval()...))>autoeval(Funcf,Args&&...args){returnf(a

c++ - auto const & map 迭代器的类型是什么? C++

我需要修复我的旧项目中的一些错误,我认为这是重构部分代码的最佳时机。我有一个具有以下结构的map:std::map>ComponentMap;在我需要遍历一些底层子map的某个地方,我使用了以下内容:for(std::map::iteratoriter=ComponentMap[compNameString].begin();iter!=ComponentMap[compNameString].end();++iter){//somecodeif(IsComponentOfType(iter,sCOMP_PRINCIPAL))iter->second->GetComponentValu

c++ - 导致运行时执行的 constexpr 仿函数中的成员

我正在使用仿函数以下列方式生成编译时计算代码(对于长代码我深表歉意,但这是我发现重现该行为的唯一方法):#include#includetemplateconstexprautocompute(constdoubleh){std::tuple,std::array>paw{};autoxtab=std::get(paw).data();autoweight=std::get(paw).data();ifconstexpr(order==3){xtab[0]=-1.0E+00;xtab[1]=0.0E+00;xtab[2]=1.0E+00;weight[0]=1.0/3.0E+00;we