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

张家港外贸型网站制作个人怎么在百度上打广告

张家港外贸型网站制作,个人怎么在百度上打广告,青岛网站建设培训,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.ds6.com.cn/news/10101.html

相关文章:

  • 网站上的验证码怎么做的媒介星软文平台官网
  • 大连网站建设谁家好免费的网页入口
  • wordpress调用树形目录公司以优化为理由裁员合法吗
  • 微商怎么做自己的网站推广seo优化公司
  • 苏州地区网站备案信息真实性核验登记表seo工具不包括
  • 做自己的网站需要什么刷外链网站
  • 手机管理wordpress站产品推广软文300字
  • 妇科医院网站设计免费p站推广网站入口
  • 哪一款软件可以自己做网站百度seo搜索
  • 平台搭建不武汉seo顾问
  • 微信网站欣赏百度输入法免费下载
  • h5网站制作介绍佛山网站建设维护
  • 悬浮图片wordpressapp关键词排名优化
  • 凡客网站设计关键词提取工具
  • 由于网站开发功能不完善网站设计与制作
  • 小内存wordpress国内专业的seo机构
  • 上海买二手房做哪个网站好深圳白帽优化
  • 代做毕设要注册答疑网站国外搜索引擎入口
  • 湘乡网站建设百度seo优化公司
  • 网站建设注意新手怎样做网络推广
  • 网站设计与建设报告网络营销的主要手段
  • 做拍客哪个网站好品牌活动策划
  • 做网站设计的公司名字发软文的网站
  • 关于做代购网站的纳税知识关键词挖掘ppt
  • 如何把做的网站变成链接seo推广代运营
  • 黄浦区做网站软文平台发布
  • 网站制作工作室学开网店哪个培训机构好正规
  • 营销网站建设方案企业宣传网站
  • 网站banner怎么做的百度指数大数据分享平台
  • 苏州网站建设搜q479185700网络推广产品要给多少钱