This blog post will show you how to create a robust and scalable logging library using lots of Modern C++ techniques. The author successfully used this code on Arduino embedded environment and various other production areas.
Let’s dive right in.
Written by Stephen Dolley
Stephen works with C++ commercial and government development teams to upgrade their skills and improve the expressiveness and robustness of their code.
With C++17 we get another facility to handle the conversion between text and numbers. Why should we care about the new routines?
Are they better in any way?
Before C++17 C++, before C++17, offered several options when it comes to string conversion:
sprintf / snprintf sscanf atol strtol strstream stringstream to_string stoi and similar functions And with C++17 you get another option: std::from_chars!
In this post, I’ll show you how to use the newest, low-level, conversion routines form C++17. With the new functionality, you can quickly transform numbers into text and have super performance compared to previous techniques.
Before C++17 Until C++17, we had several ways of converting numbers into strings:
sprintf / snprintf stringstream to_string itoa and 3rd-party libraries like boost - lexical cast And with C++17 we get another option: std::to_chars (along with the corresponding method from_chars) !
The problem: a library function offers several overloads, but depending on the implementation/compiler, some of the overloads are not available. How to check the existence of an overload? And how to provide a safe fallback?
In this article, I’ll show you a background “theory” and one case - std::from_chars that exposes full support for numbers or only integer support (in GCC, Clang).
Do you know how many ways we can implement a filter function in C++?
While the problem is relatively easy to understand - take a container, copy elements that match a predicate and the return a new container - it’s good to exercise with the Standard Library and check a few ideas.
A single-precision floating-point number is represented by 32 bits and hides various wonderful encoding techniques. However, some of those tricks might cause some imprecise calculations so it’s crucial to know how to work with those numbers.
Let’s have a look at three common misconceptions.
This is a guest post from Adam Sawicki
Two weeks ago, 20th May, I had a pleasure to talk about filtering elements on our Cracow C++ User Group online meeting.
Here are the slides and additional comments from the presentation.
Finally Restarted After a few months of break, we finally restarted our Cracow’s C++ group!
Thus far we had two presentations in 2021:
C++ Software Security Sins In the world of software development, we are up against new cybersecurity threats each day, and the risks and consequences of un-secure software are too significant to be unaware of.
Let’s review some common security threats that might lurk in our C/C++ code.
This article is an adapted version of the presentation given by Mary Kelly, supported by Embarcadero.
Before you start implementing your custom concepts, it’s good to review some goodies in the Standard Library. There’s a high chance that there’s already a predefined concept for you.
Today let’s have a look at concepts related to callable objects.
Where to find them You can find most of the predefined concepts in the <concepts> header.
According to the recent popular paper “There is plenty of room at the top”1, SW tuning will be one of the key drivers for performance gains in the near future. The growth of a single-threaded performance of modern HW is slowing down, that’s why SW tuning will become more important than it has been for the last 40 years.
Concepts are a revolutionary approach for writing templates! They allow you to put constraints on template parameters that improve the readability of code, speed up compilation time, and give better error messages.
Read on and learn how to use them in your code!
What is a concept? In short, a concept is a set of constraints on template parameters evaluated at compile time.
Before C++17, we had a few quite ugly-looking ways to write static if (if that works at compile time). For example, you could use tag dispatching or SFINAE. Fortunately, that’s changed, and we can now benefit from if constexpr and Concepts!
Let’s see how we can use it and replace some std::enable_if code.