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

张家港外贸型网站制作百度url提交

张家港外贸型网站制作,百度url提交,wordpress限制文章发布,下载人民日报客户端前言 有一节我们分析了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.tj-hxxt.cn/news/59116.html

相关文章:

  • 自由建网站的网络程序百度热搜广告位
  • 购物车功能网站怎么做的正能量网站地址链接免费
  • 做网站背景图片找培训机构的app
  • ui设计师mike个人网站广告联盟哪个比较好
  • 做网站用哪种语言好网站开发费用
  • 想找私人做网站网络营销手段有哪些方式
  • 网站建设书百度官网登录入口手机版
  • 建设一个网站需要什么人员廊坊seo推广
  • 网站建设专业网站设计公司物格网本地推广平台
  • 昆明app外包seo入口
  • 手机网站打不开被拦截怎么办网站排名软件推荐
  • 南海网站建设多少钱seo综合查询系统
  • 东莞优化疫情防控措施seo网站关键词优化报价
  • 制作网站需要什么知识网络营销网站设计
  • 网站建设新闻网络推广怎么学
  • 盈科互动武汉网站建设网络营销方式哪些
  • 网站开发类型什么意思seo是什么职位缩写
  • 海淀公司网站搭建电商平台怎么运营的
  • 如何做网站数据库电脑软件推广平台
  • 石岩附近网站建设公司哪些平台可以做推广
  • 在线做ppt的网站源代码适合30岁短期培训班
  • dw做网站的导航栏搜索指数在线查询
  • 做网站学什么语言好论述搜索引擎优化的具体措施
  • 公司网站建设接单站长之家下载
  • 网站代码查询新站如何让百度快速收录
  • 南宁百姓网官网合肥seo公司
  • 电商网站的相同点googleseo服务公司
  • 网络运维工程师有前途吗搜索引擎关键词优化有哪些技巧
  • 武汉h5网站设计sem竞价托管费用
  • 成都网站建设收费明细整站seo排名要多少钱