C++ Move特性.
来源:互联网 发布:windows 7经典主题 编辑:程序博客网 时间:2024/05/18 00:45
重要的话写前面:
它实现了移动拷贝好书和移动复制函数,从而使用右值是减少了一些不必要的临时变量的生成和复制.
#include <iostream>#include <utility>#include <vector>#include <string> int main(){ std::string str = "Hello"; std::vector<std::string> v; // uses the push_back(const T&) overload, which means // we'll incur the cost of copying str v.push_back(str); std::cout << "After copy, str is \"" << str << "\"\n"; // uses the rvalue reference push_back(T&&) overload, // which means no strings will be copied; instead, the contents // of str will be moved into the vector. This is less // expensive, but also means str might now be empty. v.push_back(std::move(str)); std::cout << "After move, str is \"" << str << "\"\n"; std::cout << "The contents of the vector are \"" << v[0] << "\", \"" << v[1] << "\"\n";}
Possible output:
After copy, str is "Hello"After move, str is ""The contents of the vector are "Hello", "Hello"
阅读全文
0 0
- Move.c && Move.h
- Move.h && Move.c
- C++ Move特性.
- C++11新特性move
- Oracle 12C 新特性之move (非分区表)table online
- 【转载】c11新特性之move介绍
- 12c online move datafile
- 【LeetCode-283】Move Zeroes(C++)
- 283. Move Zeroes (C++)
- 283.Move Zeroes(C语言)
- 283. Move Zeroes(C++/Java)
- Move
- Move
- Move
- Move..
- C++11新特性之 Move semantics(移动语义)
- C++11特性:右值引用与move语义
- c++move语义与右值引用
- 程序员的激情其实是一种痛苦
- Android 手机多媒体
- 画圆
- studio中http请求方式
- 背包问题的二进制优化
- C++ Move特性.
- Struts2国际化
- 省市联动 json ajax
- 组件、插件、控件的区别
- 编写一个计时器拦截器
- Android WebView 输入框键盘不弹出
- winfrom窗体界面加载闪屏清除
- Struts2与ajax
- Geometry