rvalue reference in C++

The rvalue reference is probably the most significant feature introduced by C++11. Let’s quickly recap what rvalue is. It is an inherited concept from C. The expression that can appear only on the right side of an assignment statement is an rvalue. However an lvalue can appear on either side of an assignment statement. But … Continue reading “rvalue reference in C++”

std::forward, Perfect Forwarding of Parameters

C++11 introduced the std::forward to preserve the value category (lvalue or rvalue) of a cv-unqualified function template parameter, that is declared as an rvalue reference, in time of passing that to another function. It forwards an lvalue either as an lvalue or as an rvalue depending on the deduced type of the template parameter. Apparently … Continue reading “std::forward, Perfect Forwarding of Parameters”

Move Assignment Operator in C++

Just like a move constructor, the move assignment operator also makes a class movable. A movable class enables efficient resource transfer from one object to another. Let’s start with an normal overloaded assignment operator. In this example, we overloaded the assignment operator in the mystring class. This overloaded function was called the object s2 was … Continue reading “Move Assignment Operator in C++”

Move Constructor, Enabling Efficient Resource Transfer in C++

From C++11, in addition to a copy constructor, we can have another special constructor called move constructor. The move constructor makes a class movable that enables efficient resource transfer. Let’s first quickly recap what a copy constructor does. We have a copy constructor in our mystring class. We created an object s1 with value “QnA … Continue reading “Move Constructor, Enabling Efficient Resource Transfer in C++”

std::move – Efficient Resource Transfer from One Object to Another

C++11 introduced this std::move() to enable efficient resource transfer from one object to another. Let’s first understand what efficient resource transfer means. We created a string object, s1, with value, ‘QnA Plus‘. We can imagine what might have happened during this s1 object creation. One constructor would have been called that allocated memory how hold … Continue reading “std::move – Efficient Resource Transfer from One Object to Another”

0
0
0
0
0
0