Archiv der Kategorie: C++

String View in C++17 (std::string_view)

The C++ string (std::string) is like a thin wrapper which stores its data on the heap. When you deal with strings it happens very often that a string copy must be created and therefore a memory allocation is done. But … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

“if constexpr” in C++17 (static if)

With C++17 the „if constexpr“ statement was introduced. This so called “static if” or “compile-time if-expression” can be used to conditionally compile code. The feature allows to discard branches of an if statement at compile-time based on a constant expression … Weiterlesen

Veröffentlicht unter C++ | 1 Kommentar

Auto Type Deduction in Range-Based For Loops

Range-based For Loops offer a nice way to loop over the elements of a container. In combination with Auto Type Deduction the source code will become very clean and easy to read and write. The Auto Type Deduction is available … Weiterlesen

Veröffentlicht unter C++ | 1 Kommentar

C++17: initializers in if-statement and switch-statement

With C++17 it is possible to initialize a variable inside an if-statement and a switch-statement. We already know and use this concept in the for-statement. To be honest: I don’t like this feature. Within this article I want to introduce … Weiterlesen

Veröffentlicht unter C++ | 2 Kommentare

Name hiding in inheritance

The C++ name hiding rules for variables are well known by software developers. In contrast, name hiding in inheritance sometimes leads to issues although it follows the same rules. Such issues are therefore not a result of the rules but … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Object Instance Creation

Whenever you write an application in C++ you will create a lot of object instances. So, this is a base development task. C++ offers several ways to initialize variables. These are not just syntactical variations for the same task. The … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

ctor types in C++

In C++ you will find several ways to initialize an object instance. For example, think about a class “MyClass” which can be constructed with a parameter. The object initialization can be done in several ways: MyClass x{y}; MyClass x(y); MyClass … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

Software Transactional Memory

One of the main challenges in multithreading applications is the access to shared memory. In case you have several software-components which want to read and write to shared memory you must synchronize these data access. The concept of Software Transactional … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

std::atomic

Within multithreading applications even trivial functions like reading and writing values may create issues. The std::atomic template can be used in such situations. Within this article I want to give a short introduction into this topic.   Atomic operations Let’s … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen

The Visitor Pattern – part 9: summary

This article is one part of a series about the Visitor pattern. Please read the previous articles to get an overview about the pattern and to get the needed basics to understand this article. As this article is the last … Weiterlesen

Veröffentlicht unter C++ | Kommentar hinterlassen