MyString(const char* p)
MyString(const MyString& str)
MyString(MyString&& str) noexcept
MyString& operator=(const MyString&str)
MyString& operator=(Mystring&& str) noexcept
virtual ~MyString()
growable containers(会发生 memory reallocation)只有两种 vector 和 deque(从中间插入元
素的时候)
You need to inform C++(specifically std::vector)that your move constructor and destructor
does not throw.
Then the move constructor will be called when the vector grows.
If the constructor is not noexcept, std::vector can't use it,
since then it can't ensure the exception guarantees demanded by the standard.
noexcept
设计一个类的时候,不知道使用者会把这个类放到哪一种容器之中,如果类有move function,
加上 noexcept
vector 动态增长
实现是一个数组,两倍成长
lvalue 可以出现于 operator=左侧者
rvalue 只能出现于 operator=右侧者
rvalue references 是 C++0x 引进来的一种新的引用类型
解决 unnecessary copying 问题,enable perfect forwarding
右值引用 rvalue references
rvalue 只能出现于 operator= 右侧
当rvalue出现于operator=(copy assignment)的右侧,我们认为对其资源进行偷取/搬移(move)
而非拷贝(copy)是可以的,是合理的
那么
1、必须有语法让我们在调用端告诉编译器“这是个 rvalue”
2、必须有语法让我们在被调用端写出一个专门处理 rvalue 的所谓 move assignment 函数
临时对象是一个右值
右值不能放在 operator=左边
std::forward
std::move
template<typename T1, typename T2>