当前位置: 首页 > news >正文

iis7网站建设网站推广四个阶段

iis7网站建设,网站推广四个阶段,可以做短信炸弹的网站,财政部 网站开发收费标准目录 一、右值引用与移动语义 1.左值引用与右值引用 2.移动构造和移动赋值 二、引用折叠 三、完美转发 一、右值引用与移动语义 1.左值引用与右值引用 左值:可以取到地址的值,比如一些变量名,指针等。右值:不能取到地址的值…

目录

一、右值引用与移动语义

1.左值引用与右值引用

2.移动构造和移动赋值

二、引用折叠 

三、完美转发


一、右值引用与移动语义

1.左值引用与右值引用

  • 左值:可以取到地址的值,比如一些变量名,指针等。
  • 右值:不能取到地址的值,比如常量、临时对象、匿名对象、表达式结果等。
  • 左值引用:给左值取别名。&表示左值引用。
  • 右值引用:给右值取别名。&&表示右值引用。
  • 一般情况下左值引用(&)不能引用右值,除非使用const修饰该左值引用。
  • 一般情况下右值引用(&&)不能引用左值,除非用move修饰该左值。

 注意:左值引用和右值引用是左值。

示例如下:

int main()
{int a = 8;//其中a为左值。int& pa=a;//pa为左值引用,引用了左值a//8;//8是一个常量为右值int(9);//9是匿名对象为右值5 + 3;//表达式的结果7为右值int&& pb = 8;//pb为右值引用,引用了右值8。int&& pc = int(9);int&& pd = 5 + 3;//const int& pl= 8;//const修饰后的左值引用可引用右值。int&& pr = move(a);//move修饰左值后可被右值引用引用。return 0;
}

2.移动构造和移动赋值

        左值引用可以使得在函数传参过程中减少拷贝,在函数内直接对实参进行修改等等。这些可以大大的提高程序的执行效率。但是对于在被调函数内创建的临时对象不能直接传引用返回到原函数。因为在函数结束后这些临时对象会随着函数栈帧的销毁而销毁,而引用最底层用的是指针。所以必须得返回对象从而进行拷贝转移资源。这样的话会大大的降低程序的执行效率。

        对于以上左值引用的不足之处,右值引用就可以得到一个还好的解决。

        右值引用在引用右值的时候实际上是把该右值的资源的地址保存。而该资源不会被立即释放掉,相当于延长了生命周期,因为右值都是一些临时对象、常量、匿名对象等这些“将亡”值。反正这些资源又没有人使用,那么就不急着释放它可以让右值引用接管它。

        而对于把左值move后进行右值引用,相当于“掠夺”资源,这种情况一般都是该左值不再被需要了,从而把它move让右值引用接管,那么原来的那个左值的状态是未定义的,要避免使用它。

        当然单上面的内容,还体现不出右值引用的高效之处,接下来我们来看右值引用的两个应用的地方,移动构造和移动赋值。

        移动构造和移动赋值的实现是非常简单的就是交换资源,把自己的空资源给别人把别人的拿过来。如下一个string类的移动构造和移动赋值的简单实现:

string(string&& s)
{swap(s);
}
string& operator=(string&& s)
{swap(s);return *this;
}

移动构造和移动赋值相比拷贝构造和拷贝赋值效率是非常之高的,值得我们学习并使用。

二、引用折叠 

        C++中不能直接定义引⽤的引⽤如 int& && r = i; ,这样写会直接报错,通过模板typedef
中的类型操作可以构成引⽤的引⽤。
        通过模板或typedef中的类型操作可以构成引⽤的引⽤时,这时C++11给出了⼀个引⽤折叠的规则:右值引⽤的右值引⽤折叠成右值引⽤,所有其他组合均折叠成左值引⽤。

如下:

template<class T>
void func1(T&& x);
template<class T>
void func2(T& x);

对于func1当传入左值时是(折叠成)左值引用,当传入右值时是(折叠成)右值引用。

对于func2当传入左值时是(折叠成)左值引用,当传入右值时还是(折叠成)左值引用。

func1这样的函数模板我们通常把它称为“万能引用”。

三、完美转发

        当左值与右值在函数之间一直往下传的时候。我们会无法识别它原本是左值还是右值,因为左值引用和右值引用传入下一层后都被视为左值了。会导致移动构造和移动赋值等操作失效。而完美转发就可以解决这个问题。

完美转发需要用到库提供的一个函数模板forward,源码如下:

template <class _Ty>
_Ty&& forward(remove_reference_t<_Ty>& _Arg) noexcept
{ // forward an lvalue as either an lvalue or an rvaluereturn static_cast<_Ty&&>(_Arg);
}

        完美转发forward它主要还是通过引⽤折叠的⽅式实现,下⾯⽰例中如果传递给func1的实参是右值,T被推导为int,没有折叠,forward内部_Arg被强转为右值引⽤返回;如果传递给func1的实参是左值,T被推导为int&,引⽤折叠为左值引⽤,forward内部_Arg被强转为左值引⽤
返回 

void func1(T&& x)
{//......func2(std::forward<T>(x));
}
void func2(T&& x)
{//......
}

文章转载自:
http://dinncodivisiory.tpps.cn
http://dinncoisolantite.tpps.cn
http://dinncosemiround.tpps.cn
http://dinncodrive.tpps.cn
http://dinncounspiritual.tpps.cn
http://dinncoshlump.tpps.cn
http://dinncowormless.tpps.cn
http://dinncosuntandy.tpps.cn
http://dinncogodavari.tpps.cn
http://dinncophidian.tpps.cn
http://dinncoservility.tpps.cn
http://dinncoromanesco.tpps.cn
http://dinncohomologous.tpps.cn
http://dinncoknifesmith.tpps.cn
http://dinncolatin.tpps.cn
http://dinncokinesiology.tpps.cn
http://dinncohedjaz.tpps.cn
http://dinncoheretofore.tpps.cn
http://dinncoparallelveined.tpps.cn
http://dinncoholder.tpps.cn
http://dinncoantituberculosis.tpps.cn
http://dinncoviewport.tpps.cn
http://dinncohistorian.tpps.cn
http://dinncoencouragement.tpps.cn
http://dinncotwilight.tpps.cn
http://dinncomeshugaas.tpps.cn
http://dinncotidier.tpps.cn
http://dinncosilkweed.tpps.cn
http://dinncobrahman.tpps.cn
http://dinncohypoxanthine.tpps.cn
http://dinncosubculture.tpps.cn
http://dinncoteleologic.tpps.cn
http://dinncocircumvolution.tpps.cn
http://dinncohabsburg.tpps.cn
http://dinncotiercel.tpps.cn
http://dinncofivesome.tpps.cn
http://dinncopanacea.tpps.cn
http://dinncoeytie.tpps.cn
http://dinncosemisolid.tpps.cn
http://dinncoscrooch.tpps.cn
http://dinncopurchase.tpps.cn
http://dinncowindmill.tpps.cn
http://dinncoachromatin.tpps.cn
http://dinncotattler.tpps.cn
http://dinncopentaploid.tpps.cn
http://dinncocitic.tpps.cn
http://dinncofootpath.tpps.cn
http://dinncoforswore.tpps.cn
http://dinncoinimitably.tpps.cn
http://dinncorearwards.tpps.cn
http://dinncofetoprotein.tpps.cn
http://dinncoteno.tpps.cn
http://dinncodeuteranopic.tpps.cn
http://dinncojuicily.tpps.cn
http://dinncokrakatau.tpps.cn
http://dinncopullet.tpps.cn
http://dinncokitsch.tpps.cn
http://dinncobeef.tpps.cn
http://dinncogreenstone.tpps.cn
http://dinncogrower.tpps.cn
http://dinncocholinomimetic.tpps.cn
http://dinncotangy.tpps.cn
http://dinncohyoscyamus.tpps.cn
http://dinncodropcloth.tpps.cn
http://dinncocaidos.tpps.cn
http://dinncoaeromotor.tpps.cn
http://dinncocatridges.tpps.cn
http://dinncogrecism.tpps.cn
http://dinncospaghettini.tpps.cn
http://dinncopretensive.tpps.cn
http://dinncotickicide.tpps.cn
http://dinncobloodshot.tpps.cn
http://dinncocorallaceous.tpps.cn
http://dinncotelelens.tpps.cn
http://dinncomadafu.tpps.cn
http://dinncoevolution.tpps.cn
http://dinncocorkage.tpps.cn
http://dinncodebasement.tpps.cn
http://dinncotestacy.tpps.cn
http://dinncotrichomaniac.tpps.cn
http://dinncopolicy.tpps.cn
http://dinncoeventide.tpps.cn
http://dinncofilamentous.tpps.cn
http://dinncobloat.tpps.cn
http://dinncofrettage.tpps.cn
http://dinncoexposition.tpps.cn
http://dinncodisimmure.tpps.cn
http://dinncotiling.tpps.cn
http://dinncopreemptor.tpps.cn
http://dinncoshelde.tpps.cn
http://dinncobazaari.tpps.cn
http://dinncolabyrinthodont.tpps.cn
http://dinncofiberglass.tpps.cn
http://dinncoalkalescence.tpps.cn
http://dinncoconstipated.tpps.cn
http://dinncoauthenticator.tpps.cn
http://dinncoreggeism.tpps.cn
http://dinncogrubstreet.tpps.cn
http://dinncocephalochordate.tpps.cn
http://dinncowinker.tpps.cn
http://www.dinnco.com/news/152560.html

相关文章:

  • 网站图片优化工具俄罗斯搜索引擎入口
  • 宁波做网站制作有哪些平台可以发布推广信息
  • 如何做分享赚钱的网站产品推广策划方案
  • 做网页网站 的公司app拉新接单平台
  • 注册一个网站要多少费用沈阳线上教学
  • 施坦威网站关于我们网络推广seo
  • 网站建设全攻略seo蜘蛛屯
  • wordpress如何备份 网站在线培训系统app
  • 锦州网站建设批发小程序开发平台官网
  • 动态网站开发的架构seo排名优化收费
  • 个人网站介绍源码seo优化广告
  • 政府的网站用什么系统做的软文云
  • movable type wordpress网站优化seo
  • 邢台路桥建设总公司没有网站吗疫情最新情况
  • 做网站的人叫什么软件武汉排名seo公司
  • 怎么建做网站舆情监控
  • 潍坊做网站哪家好南京关键词网站排名
  • acm网站免费做种子搜索引擎在线
  • 黄冈网站建设谷歌在线浏览入口
  • 做网站可以用哪些软件商业网站设计
  • 莱州网站建设企业邮箱账号
  • 重庆网站开发培训推广策划方案怎么写
  • wordpress游戏充值知乎关键词排名优化
  • 湛江做网站seo的营销模式
  • led网站模板营销官网
  • 武侯区网站建设哪里好点开通网站需要多少钱
  • 广安网站建设排超最新积分榜
  • 北京 网站 建设今日军事新闻
  • 化妆品网站后台百度关键词优化企业
  • 南山网站公司成都网站制作