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

张家港外贸型网站制作汽车推广软文

张家港外贸型网站制作,汽车推广软文,毕业设计网站开发选题依据,视频手机网站开发前言 有一节我们分析了std::bind的实现原理,本节稍作休息分析一个比较简单的std::move 原理 std::move的原理太简单了,一句话:就是把传进来的参数强转为右值引用类型。作用为调用移动构造函数,或移动赋值函数。下面通过例子和代…

前言

有一节我们分析了std::bind的实现原理,本节稍作休息分析一个比较简单的std::move

原理

std::move的原理太简单了,一句话:就是把传进来的参数强转为右值引用类型。作用为调用移动构造函数,或移动赋值函数。下面通过例子和代码说明。

例子

#include <iostream>
#include <cstring>using namespace std;struct Thing {Thing(){cout << "default construct\n";}// Copy operatorThing(const Thing& other){cout << "copy constructor\n";}// Move constructorThing(Thing&& other) noexcept{cout << "move constructor\n";}// assignment operatorThing& operator=(const Thing& rhs) {cout << "copy operator\n";return *this;}// move assignment operatorThing& operator=(Thing&& rhs) noexcept {cout << "move operator\n";return *this;}// destructor necessary since we are working in dangerous new/delete territory~Thing() noexcept {cout << "destructor " << "\n";}
};
int main()
{cout << "main::constructing a\n";Thing a;cout << "main::moving a to newly constructed c\n";Thing c(std::move(a));Thing x = std::move(c);cout << ">main::thing y\n";Thing y;y = std::move(x);return 0;
}

[mzhai@c++11]$ ./a.out
main::constructing a
default construct
main::moving a to newly constructed c
move constructor //Thing c(std::move(a));
move constructor //Thing x = std::move©;
main::thing y
default construct
move operator //y = std::move(x);
destructor
destructor
destructor
destructor

a, c, x虽然都是左值,但std::move却把它们强转成了右值引用,从而调用了move语义的函数而不是copy语义的。

std::move源码

 92   /**93    *  @brief  Convert a value to an rvalue.94    *  @param  __t  A thing of arbitrary type.95    *  @return The parameter cast to an rvalue-reference to allow moving it.96   */97   template<typename _Tp>98     constexpr typename std::remove_reference<_Tp>::type&&99     move(_Tp&& __t) noexcept
100     { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }

让我们看看remove_reference 的定义,看看它是怎么脱去类型的外衣的:

1402   /// remove_reference
1403   template<typename _Tp>
1404     struct remove_reference
1405     { typedef _Tp   type; };
1406
1407   template<typename _Tp>
1408     struct remove_reference<_Tp&>
1409     { typedef _Tp   type; };
1410
1411   template<typename _Tp>
1412     struct remove_reference<_Tp&&>
1413     { typedef _Tp   type; };

原来不管你原来的类型是左值引用还是右值引用,统统都定义type为脱去外衣的类型。

http://www.dt0577.cn/news/29601.html

相关文章:

  • 手机网站注意哪些问题百度推广如何计费
  • 自己开发小程序多少钱咸阳seo
  • ppt在线制作网页德州seo优化
  • 网站单页支付宝支付怎么做的产品怎么在网上推广
  • 什么公司网站建设做的好企业网站的推广方法有哪些
  • 条件查询 php网站源码搜盘 资源网
  • 网站建设商务的术语谷歌的推广是怎么样的推广
  • l网站建设如何在百度上推广业务
  • 做网站挣钱快吗seo排名优化工具
  • 网站项目怎么做的编程培训机构加盟哪家好
  • 医院网站建设水平自动点击器怎么用
  • 延吉建设局网站汕头seo网站推广
  • 完备的网站建设推广专业竞价托管
  • wordpress 欢迎插件企业关键词排名优化网址
  • 个人做电梯网站seo教学免费课程霸屏
  • 网站源码带后台seo的优点
  • 做电脑网站用什么软件好用吗关键词首页排名代发
  • 英文网站模板cms北京全网营销推广
  • 廊坊做网站哪家好广东培训seo
  • wordpress 小人百度seo优化排名
  • 做网站图片多少钱南宁seo排名外包
  • 代办执照seo是什么意思电商
  • 中国建设银行青岛分行网站产品软文范例
  • 成功案例 品牌网站百度平台商家客服电话
  • 关于建设集团公司网站的报告广告平台推广渠道
  • 工商企业年报查询入口广州seo技术外包公司
  • 南桥做网站随州seo
  • 网站定制案例怎样做一个产品营销方案
  • 东莞东城做网站公司惠州seo关键字优化
  • 多语种外贸网站建设得物app的网络营销分析论文