Rubbish time debug

Like many people, I prefer to use QT Creator as an IDE. I use CMake on my projects ,which are not QT applications, instead of qMake. And Using XCode seems to me irrelevant, don’t judge me.

Anyways, I decided to open one of them on VSC, my favourite ide on GoLang and TypeScript. At the bargaining everything was fine but I disappointed when I use one breakpoint. Lldb doesn’t work on it because of these XCode updates.

I spend lots of lots of time to fix it. But the solution was on. Just Easy, Install CodeLLDB, and create launch.json and add automatic lines.

I don’t know why I spent that time on that. There was an easy solution, in front of me.

To be Modern or Not

C++

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

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

Lambda

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.

Boris Jhonson and Coronavirus

Here, in Great Britain, nobody knows what will happen to us. We live in the corona attack and Mr Jhonson’s careless approach. As a Turkish guy, I don’t clearly understand why these English Politicians ignore this situation. I thought Turkey isn’t part of the modern free world. But I learn that our government and Mr Erdogan really responsible person.

It is really interesting information for me. I was blind about our culture. That is really human-oriented.

Covid lives in our mobiles too

At the same time, I mention that social media is really important in our life. And I know that Covid-19 will destroy anything but I also recognize that there is another virus in our mobile phone. A social media virus, that brings many viral pieces of information generally false, hoax. This Hoax-Covid-19-Social virus not only infects our mobiles and also our brains. The human language uses in this virus. It doesn’t have any computer zeros and ones.

By the way, we will see what will happen soon.

What do I do now?

The best wat is staying at home. And spending time. The best option is reading. Yes, it is a very new blog I know but if you want you can read my post such as Perfect Forwarding with Template to dive in C++11/14-17 or 20.

And I also spend my time on the CPA test too.

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

Template

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.