C++ Promise and Future

C++11 introduced the concept of promise and future to a provide synchronization point between threads by sharing objects. The promise object owner (the producer thread) promises to produce a value – may not be immediately but sometime in future. The future owner (the consumer thread) expects a value once the associated promise is met by … Continue reading “C++ Promise and Future”

std::move vs std::forward

The std::move and std::forward are used to serve two different purposes. The std::move enables move semantic for efficient resource transfer from one object to another. Whereas, the std::forward is used to preserve the value category (lvalue or rvalue) of the parent function’s template parameter in time of calling another function. This feature is also known … Continue reading “std::move vs std::forward”

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”

Assignment Operator Overloading in C++

In C++, we can overload an operator for a user defined class to change its default behavior. C++ provides a default assignment operator, “=”, that provides member by member copy. This default behavior of the assignment operator does not always produce desired result. The default assignment operator has the exact same problem that a default … Continue reading “Assignment Operator Overloading in C++”

0
0
0
0
0
0