当前位置: 首页 > 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.ds6.com.cn/news/121113.html

相关文章:

  • 深圳企业网站建设费用明细福州seo
  • 高清做 视频在线观看网站电商网站前端页面内容编写
  • 装修公司全屋整装谷歌aso优化
  • 清爽网站什么是引流推广
  • 辽宁建设工程信息网 招标文件福州seo关键字推广
  • 在线客服系统网站源码如何做谷歌seo推广
  • 自己免费做网站(四)百度推广登陆
  • 做网站创业需要注册公司吗凤山网站seo
  • 网络运维工程师简历怎么写南京seo外包平台
  • 公司的官方网站的作用公司主页网站设计
  • 营销型网站建设服务长春网站优化体验
  • 网站自动化开发百度网络优化推广公司
  • 有什么自学网站建设的网站百度查找相似图片
  • 网站建设与软件开发哪个好赚钱百度网络推广
  • 沈阳做网站客户多吗能打开各种网站的浏览器下载
  • wordpress主题申请软著吗seo技巧
  • 自己做本地视频网站百度知识营销
  • 河北邢台专业做网站手机网页设计制作网站
  • 东营网站建设培训关键词排名关键词快速排名
  • smluntan论坛wordpress潍坊seo按天收费
  • 易语言 网站开发亚马逊关键词优化怎么做
  • 女的男的做那个视频网站seo建站工具
  • 谁有学做网站论坛账号宁波seo外包推广公司
  • 关于政府网站建设工作讲话今天刚刚发生的新闻最新新闻
  • 布吉做棋牌网站建设找哪家效益快软文营销写作技巧
  • 网站如何做谷歌推广郑州seo线下培训
  • 江苏分销网站建设口碑营销的例子
  • 为博彩做网站日入两万站长统计app软件下载2021
  • 宜昌网站优化今年疫情最新消息
  • 网站建设多维关键词竞价排名是什么意思