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

电信做网站吗百度站长工具验证

电信做网站吗,百度站长工具验证,seo网站排名优化方案,桐庐县网站建设前言 有一节我们分析了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.yayakq.cn/news/248792/

相关文章:

  • 手把手做网站牙科医院网站推广方案
  • 建设小辣猫的网站北京网站改版多少钱
  • 建高铁站赚钱吗安徽建设工程信息网查工程师询平台
  • 泉州建设系统培训中心网站富阳公司做网站
  • 企业网站制作深圳网站发布流程
  • 做期货的的都喜欢去什么网站网页美工实训心得
  • 广州企业建站系统模板nodejs网站毕设代做
  • 外卖网站那家做的好wordpress右键菜单插件
  • h5个人网页设计心得给甜品网站做seo
  • 大连网站建设兼职wordpress 短信登录密码错误
  • 福建省建设执业注册中心网站wordpress页面顶部登录
  • 公司网站内容的更新北京建工集团有限公司官网
  • 有微重庆网站吗wordpress教育主题
  • 贵阳两学一做网站晋城门户网站建设
  • 开发小型门户网站的方法 步骤常州网站建设公司案例
  • 药店网站源码百度一下百度首页官网
  • p2p网站建设做微信活动是做网站还是做小程序好
  • 东莞网站建设推广有哪些wordpress著名插件
  • 免费网站的app怎样设计电子商务网站的建设
  • 做暖暖视频免费观看免费网站wordpress关闭自动更新
  • 佛山制作网站设计报价怎么给客户谈做网站
  • ·温州公司建设网站南昌网站优化
  • 修改数据库密码 进不了网站后台双wordpress自动同步文章
  • 做网店去哪个网站货源好为企业做好服务保障
  • 小地方的旅游网站怎么做wordpress修改字体
  • 网站可信认证必须做吗公司名称怎么取名
  • 怎么不花钱建立网站网站开发模板下载
  • 南宁做网站公司品牌云尚网络网站虚拟主机行吗
  • 网站姐姐做床戏网站平台公司实体化转型
  • 建网站 视频的网址深圳商城网站建设公司