Tsallaka zuwa abun ciki
Justice Tech School

Move Semantics

std::move turns a value into an rvalue so its resources can be moved instead of copied.

Example
#include <iostream>
#include <string>
#include <utility>

int main() {
  std::string a = "hello";
  std::string b = std::move(a);
  std::cout << b << " " << a.size() << "\n";
  return 0;
}

Result

hello 0

Exercise

Move.

std::(a)

Quiz Test

What does moving avoid?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.