草庐IT

integer_ref

全部标签

c++ - const ref lvalue to non-const func return value 是否专门减少拷贝?

我遇到了一个C++习惯,我试图研究它以了解它的影响并验证它的用法。但我似乎找不到确切的答案。std::vectorgetThings();voiddo(){conststd::vector&things=getThings();}这里我们有一些返回非const&值的函数。我看到的习惯是在分配函数的返回值时使用const&左值。提出这个习惯的原因是它减少了拷贝。现在我一直在研究RVO(返回值优化)、复制省略和C++11移动语义。我意识到给定的编译器可以选择阻止通过RVO进行复制,不管这里是否使用了const&。但是,在防止复制方面,const&左值的使用对非const&返回值有任何影响吗

c++ - 带有 ref_qualified 成员函数的 std::mem_fn

有什么方法可以通过std::mem_fn使用ref限定的成员函数?下面的代码编译失败:classDeadPool{public:voidjump()&{std::cout错误信息:mem_fn_ex.cc:18:15:error:nomatchingfunctionforcallto'mem_fn'autocobj=std::mem_fn(&DeadPool::jump);//Won'tcompile^~~~~~~~~~~/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/functional:1233:1:not

c++ - 海湾合作委员会 4.1.2 : error: integer constant is too large for ‘long’ type

我编译了一段关于散列函数的代码并得到了错误:整数常量对于‘long’类型来说太大了。我用谷歌搜索了一下,它说要添加后缀“ULL”,但我确实有ULL作为后缀。这个后缀只有gcc4.4.1支持,我机器上只有gcc4.1.2,不允许安装新的编译器。有什么方法可以更改代码以解决问题吗?谢谢,-托尼unsignedlonglonghash(stringk){//FNVhashunsignedlonglongx=14695981039346656037ULL;for(unsignedinty=0;y 最佳答案 1099511628211对于(3

c++ - 为什么 lambda 会删除 cv 和 ref?

给定一个lambda:autof=[](constT&var){returnvar;};为什么f的返回类型是T(不是constT&)?这在标准中的什么位置? 最佳答案 重点是:使用auto进行返回类型推导采用模板类型推导规则。返回类型被声明为按值传递;这意味着用于推导的表达式的引用性和顶级cv限定符(即var)将被忽略。标准引述:关于auto:Iftheplaceholderistheautotype-specifier,thededucedtypeT'replacingTisdeterminedusingtherulesforte

已解决java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String异常的

已解决java.lang.ClassCastException:classjava.lang.Integercannotbecasttoclassjava.lang.String异常的正确解决方法,亲测有效!!!文章目录报错问题解决思路解决方法交流报错问题java.lang.ClassCastException:classjava.lang.Integercannotbecasttoclassjava.lang.String解决思路java.lang.ClassCastException:classjava.lang.Integercannotbecasttoclassjava.lang.St

c++ - std::string& 与 boost::string_ref

如果我在std::string&上使用boost::string_ref还重要吗?我的意思是,在处理字符串时,使用boost::string_ref真的比std版本更有效吗?我真的不明白这里提供的解释:http://www.boost.org/doc/libs/1_61_0/libs/utility/doc/html/string_ref.html.真正让我感到困惑的是std::string也是一个仅指向分配内存的句柄类,并且自c++11以来,具有移动语义的复制操作在上面的文章中提到不会发生。那么,哪个更有效? 最佳答案 strin

c++ - std::ref 和 swap 函数似乎不能很好地协同工作

templatevoidmyswap(Ta,Tb){Ttemp=a;a=b;b=temp;}intmain(){intm(20),n(30);myswap(ref(m),ref(n));//misstill20andnisstill30}为什么m和n的值没有互换?将包装在std::ref中的值传递给INCREMENT函数会导致原始变量(调用INCREMENT函数的堆栈帧中的变量)中的值发生变化。或者,std::ref的使用是否受到限制? 最佳答案 std::ref(及其关联的std::reference_wrapper)是为标准库中

c++ - 根据 value_type 调用适当的构造函数 : integer or float

我有一个函数,它使用均匀分布将最小值和最大值之间的随机值填充到容器中。#include#include#include#includetemplatevoiduniform_random(TContainer&container,consttypenameTContainer::value_typemin,consttypenameTContainer::value_typemax){std::random_devicerd;std::mt19937gen(rd());//Belowlinedoesnotworkwithintegerscontainerstd::uniform_rea

c++ - libpng 错误 : PNG unsigned integer out of range

当尝试从内存中读取PNG时,我遇到了这个奇怪的错误:libpngerror::PNGunsignedintegeroutofrange这个错误是由引起的png_read_info(png_ptr,info_ptr);它使用以下处理程序:staticvoidReadDataFromBuffer(png_structppng_ptr,png_bytepoutBytes,png_size_tbyteCountToRead){PNGDataPtrdataptr=(PNGDataPtr)png_get_io_ptr(png_ptr);png_uint_32i;coutlenpdataptr->l

c++ - 显式默认/删除的函数可以在 ref 限定符上重载吗?

简介Refqualifiers:一种消除隐含对象的rl-valuness歧义的方法。作为一个简单的例子,以下面的类为例classexample{intmember;public://...int&value()&;//^int&&value()&&;//^^intconst&value()const&;//^};使用此C++11功能(用^标记的语法),允许我们控制将用value()的版本p>左值临时工常量左值实际上ref限定适用于类的*thisDefaulted/Deletedfunctions:将一个特殊成员函数指定为编译器生成(默认)定义或不可访问(删除)。举个例子structty