To be Modern or Not


C++ has great change after C++11 and it still continues. I shared some of the basic important topics before. But I wish to add a summary here ;

I hope it helps

Mutex and Atomics

To protect value with a simple mutex.

The other way is using unique_lock but it locks threat critically

New Memory model Atomic

Atomic brings us a secure model to reach data on memory. However, it is slower than the simple mutex operation, atomic types make us sure about memory sharing.


Threat alive

In C++ you can provide concurrency by using threat.

join method creates waiting for the main thread. But detach stop connection between the main thread and created child thread.

Passing argument

You can also pass an argument to the thread. You can simply use the parameter on thread method.

But it creates several copies of the object. The best way is using pointer but you can’t pass pointer directly. There is a helper std:ref

on the other hand, you may use std:cref for constant references

Using the same variables with mutex

If multiple threads use a variable. You have to create a mutex system. A mutex has two important methods: lock and unlock.



Lambda is a method to create a function object in C++. The basic structure is:

To get the type of the lambda;

You may mention that lambda is a function object.

If you using C++14 or letter. you can use auto keyword to create template lambda. To change your Cmake setting please check the flowing line.

and the using auto on C++

importing a variable as copy

the way to mutate a capture item

the best way to mutate variable out of the scope is using referance capture item.

To use all variables in the scope and also global just use & sign in capture list f lambda

And = for using copies.

Variadic Template

In C++ templates may use to declare to get several version

In here you may find a way to declare a type called Param but not only one strict type.

You may use it with other type names to

And of course, you may create a function that calls himself recursively. But it needs its empty version too.

forward method may be used for possible move constructors.

Sizeof… is a standard method to get the count of the nested arguments.

Perfect Forwarding with Template

By writing a constructor template you can cover several alternatives of the constructors.

But there is also a way to call copy constructor or move constructor when you forwarding an object.

In flowing code, we provided a Has-A type class to understand what type of constructor called.

In the Has-A class, we implemented 4 types of initialization 2 for copy and 2 for the move. You may mention that std::mode has been used to forward parameter without creating a copy of it.

Template method have been used on the MyClass Class and it uses std:: forward method.

std::forward is a template method which looks the type of typetypes. If the type of the template is a reference type, it creates a copy of the object, otherwise moves the object.

Non-type Template in Array

You can pass size of an array by only using a template parameter. Here is an example code of it


Here you are a short review code for templates

Explicit Initialization forces compiler to create a version of code.

Explicit Specialization is the way for creating an alternative implementation of a template method.

Deconstructors can’t throw

You cant throw an exception from a deconstruction method of a class because all destroy methods are noexcept(true).

Diamond Inheritance

virtual keyword on multiple base class creates one and only copy