std::weak_ptr in C++

The std::weak_ptr is part of the smart pointer family introduced in C++11 which holds a non-owning reference to an object managed by other std::shared_ptr(s). It does not own the object means that the existence of a std::weak_ptr does not ensure the validity of the referred object. If all the std::shared_ptr(s), owing the object, get destroyed, … Continue reading “std::weak_ptr in C++”

std::async – Execute a Function Asynchronously

The function template, std::async, allows us to run a function (possibly time consuming) asynchronously. The actual function, that needs to be executed asynchronously, is passed to this std::sync. The std::sync returns a future object immediately without waiting for the passed function to finish execution. When the function execution will start depends of the options passed … Continue reading “std::async – Execute a Function Asynchronously”

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++”

0
0
0
0
0
0