Values & References12 / 16
Up next

std::move

#include <print>
#include <string>
#include <utility>

int main() {
    std::string src = "a long string that owns a heap buffer";
    // move steals src's buffer; no character is copied
    std::string dst = std::move(src);
    std::println("{}", dst);
    // src is now valid but unspecified (typically empty)
    std::println("moved-from size: {}", src.size());
}
What you're solving

hand off a resource instead of copying