Wikipedia Page on C++11 R-value references and move constructors
- In C++11, in addition to copy constructors, objects can have move constructors.
(And in addition to copy assignment operators, they have move assignment operators.) - The move constructor is used instead of the copy constructor, if the object has type “rvalue-reference” (
Type &&
). std::move()
is a cast that produces an rvalue-reference to an object, to enable moving from it.
It’s a new C++ way to avoid copies. For example, using a move constructor, a std::vector
could just copy its internal pointer to data to the new object, leaving the moved object in an moved from state, therefore not copying all the data. This would be C++-valid.
Try googling for move semantics, rvalue, perfect forwarding.
Related Posts:
- What is move semantics?
- What is a lambda expression in C++11?
- What is a smart pointer and when should I use one?
- What does T&& (double ampersand) mean in C++11?
- push_back vs emplace_back
- push_back vs emplace_back
- Why should I use a pointer rather than the object itself?
- What are the differences between a pointer variable and a reference variable in C++?
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- Why is “using namespace std;” considered bad practice?
- What is an undefined reference/unresolved external symbol error and how do I fix it?
- ld: symbol(s) not found for architecture x86_64 error
- What does the explicit keyword mean?
- What is the ‘override’ keyword in C++ used for? [duplicate]
- Meaning of = delete after function declaration
- C++ std::priority_queue uses the lambda expression
- Usage and Syntax of std::function
- What exactly is nullptr?
- What does the explicit keyword mean?
- Why is enum class preferred over plain enum?
- Difference between `constexpr` and `const`
- Split a string using C++11
- How to create timer events using C++ 11?
- What is the difference between const int*, const int * const, and int const *?
- Segmentation fault error 11 C++
- What is the difference between const int*, const int * const, and int const *?
- Why doesn’t C++ have a garbage collector?
- Compiling C++11 with g++
- terminate called after throwing an instance of ‘std::invalid_argument’ what(): stoi
- What exactly is std::atomic?
- Issue with std::stol – ‘std::invalid_argument’ what(): stol
- terminate called after throwing an instance of ‘std::out_of_range’
- Cleanest way to copy a constant size array in c++11
- undefined reference to ‘std::cout’
- expression preceding parentheses of apparent call must have (pointer-to-) function type
- C++ error: Undefined symbols for architecture x86_64
- C++ terminate called without an active exception
- Thread pooling in C++11
- Is the practice of returning a C++ reference variable evil?
- How does std::forward work? [duplicate]
- How to write C++ getters and setters
- Difference in make_shared and normal shared_ptr in C++
- What are the differences between struct and class in C++?
- C++: std does not have member “string”
- gcc/g++: “No such file or directory”
- error: use of deleted function
- Resolve build errors due to circular dependency amongst classes
- Call to implicitly deleted copy constructor in LLVM
- cc1plus: error: unrecognized command line option “-std=c++11” with g++
- std::wstring VS std::string
- error C2679: binary ‘<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
- What is object slicing?
- no match for ‘operator<<’ in ‘std::operator
- Warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11?
- Use the auto keyword in C++ STL
- Call to non-static member function without an object argument compiler error
- Does C++11 have C#-style properties?
- Iterator Loop vs index loop
- initialize a vector to zeros C++/C++11
- When is it safe to call this-> in constructor and destructor
- How to memset char array with null terminating character?
- How well is Unicode supported in C++11?
- How to automatically convert strongly typed enum into int?
- too many initializers for ‘int [0]’ c++
- overloaded function with no contextual type information
- Creating folders in C++
- convert string to size_t
- Compiling C++11 with g++
- ERROR C2039: ‘vector’: is not a member of ‘std’
- Does static constexpr variable inside a function make sense?
- c++ vector bubble sort
- How to use bitmask?
- Differences between unique_ptr and shared_ptr
- Floating point exception( core dump
- Passing Arrays to Function in C++
- Identifier not found error on function call
- Debug assertion failed. C++ vector subscript out of range
- What causes a SIGABRT fault?
- Graphics Library for C++
- warning: ISO C++ forbids variable length array
- cin >> “no operator matches these operands”
- C++ Structure Initialization
- How to convert vector to array
- cannot declare variable ‘’ to be of abstract type ‘’
- Difference between ‘struct’ and ‘typedef struct’ in C++?
- How to project a point onto a plane in 3D?
- Using C-string gives Warning: “Address of stack memory associated with local variable returned”
- generate random double numbers in c++
- Cygwin Make bash command not found
- C++ Compiler Error C2280 “attempting to reference a deleted function” in Visual Studio 2013 and 2015
- C++ error: undefined reference to ‘clock_gettime’ and ‘clock_settime’
- Initializing pointers in C++
- Static vs dynamic type checking in C++
- “No rule to make target ‘install'”… But Makefile exists
- Is it still safe to delete nullptr in c++0x?
- Declaration is incompatible with type
- One or more multiply defined symbols found
- I’m getting the error “stoi is not a member of std” in myprogramminglab [duplicate]
- Template constructor in a class template – how to explicitly specify template argument for the 2nd parameter?
- C++ float array initialization