Modern C++ Programming Cookbook – Third Edition
Marius Bancila's Blog
by Marius Bancila
1M ago
The Third Edition of my book, Modern C++ Programming Cookbook (ISBN 978-1835080542) has been published by Packt. The book can be ordered from Amazon and Packt. The book is organized in recipes, much like a cookbook. These recipes, in turn, are organized in sections that introduce you to the topic, list any necessary pre-requisites and then explain how to do something and how that works. This second edition comes with more than 150 recipes covering language and library features from C++11/14/17/20/23, including the libraries for strings, containers, algorithms, iterators, input/output, regular ..read more
Visit website
Formatting Text in C++: The Old and The New Ways
Marius Bancila's Blog
by Marius Bancila
7M ago
When it comes to format a piece of text in C++ there are several ways you can employ: I/O streams, particularly std::stringstream with stream operations (such as operator <<) printf family of functions, particularly sprintf the C++20 format library, particularly std::format / std::format_to any 3rd party library, {fmt} in particular (the source of the new standard format library) The first two options represent the old ways. The format library, is, obviously, the new, modern way of formatting text. But which is better in terms of performance? Let’s try to figure out. In which examples ..read more
Visit website
How to convert an enum to string in C++
Marius Bancila's Blog
by Marius Bancila
8M ago
Enumerations are widely used and we often need to convert enum values to strings (typically for recording values in logs) but there is no option at the language level or a utility in the standard library to make it possible. Therefore, developers are usually handcrafting their own solutions. Let’s say we have the following enum: enum person { funny, smart, intelligent }; The simplest solution to convert the values to strings is to write a function such as this: const char* to_string(person p) { switch(p) { case person::funny: return "funny"; case person::smart ..read more
Visit website
The curious case of error C2065: ‘IID_InterfaceName’: undeclared identifier
Marius Bancila's Blog
by Marius Bancila
8M ago
Recently, I stumbled across a peculiar error that I found nothing about on the web. Although I got rid of it, I didn’t figure out what the problem was. This post is merely the story of what happened. I am working on a project that contains both C++ and C# projects. The C++ ones used to be built with /std:c++17 and we wanted to upgrade. So I switched to /std:c++latest and /std:c++20 for those containing C++/CLI code. Of course, this didn’t come for free, I had to fix a large amount of errors first, but in the end everything was building and working fine. Except that it didn’t. The next day afte ..read more
Visit website
How to make chunks of a range in C++23
Marius Bancila's Blog
by Marius Bancila
1y ago
Last year, I wrote a blog post about new C++23 range adaptors for joining and zipping. The C++23 standard includes a longer lists of range adapters (you can find a list here). Among them, there are several adaptors used for creating views consisting of chunks or “windows” of the elements of a given range. In this blog post, I will present these adaptors. adjacent std::ranges::adjacent_view is a range adaptor that takes a view and produces a new view whose elements are windows of N adjacent elements of the original view. To understand this better, let’s consider we have a view consisting of the ..read more
Visit website
The C++23 standard break-down
Marius Bancila's Blog
by Marius Bancila
1y ago
It’s almost the eve of 2023 and the C++23 standard is feature complete for some while. At some point next year, the new standard version will be formally approved and we will officially have a new version of the standard. But compilers and library implementors are already supporting some of the new additions (or updates) to the standard. If you haven’t been following closely the evolution of C++23 you are probably wondering what’s in this new version. In this article, you will find a list of the most significant changes to the standard. There is actually quite a long list of proposals that hav ..read more
Visit website
My book “Template Metaprogramming with C++” is now available
Marius Bancila's Blog
by Marius Bancila
1y ago
I am pleased to announce that my latest book, Template Metaprogramming with C++ (ISBN 9781803243450), has been published by Packt and can be ordered from both Amazon and Packtpub. What is this book about? This book is focused entirely on templates and metaprogramming. You will learn everything from template syntax to variadic templates, from template recursion to argument deduction. You will explore in detail type traits and conditional compilation, constraints and concepts, as well as a variety of patterns such as the Curiously Recuring Template Pattern, mixins, type erasure, type dispatchi ..read more
Visit website
Using the C++23 std::expected type
Marius Bancila's Blog
by Marius Bancila
1y ago
The C++23 standard will feature a new utility type called std::expected. This type either contains an expected value, or an unexpected one, typically providing information about the reason something failed (and the expected value could not be returned). This feature is, at this time, supported in GCC 12 and MSVC 19.33 (Visual Studio 2022 17.3). In this article, we’ll see what std::expected is and how it can be used. Why do we need std::expected? Suppose you have to write a function that returns some data. It has to perform one or more operations that may fail. This function needs to return th ..read more
Visit website
Requires expressions and requires clauses in C++20
Marius Bancila's Blog
by Marius Bancila
1y ago
The C++20 standard added constraints and concepts to the language. This addition introduced two new keywords into the language, concept and requires. The former is used to declare a concept, while the latter is used to introduce a requires expression or a requires clause. These two could be confusion at first, so let’s take a look at which is which and what is their purpose. Let’s start with the following example: In this snippet, we have the following: A concept, called Composable, whose body consists of a requires expression (containing a single constraint). The requires expression is requ ..read more
Visit website
Unwrapping WinUI3 for C++
Marius Bancila's Blog
by Marius Bancila
2y ago
The Windows UI Library 3, known shortly as WinUI 3, is a native UI framework that ships with the Windows App SDK. This is an SDK complementary to the Windows SDK, WPF, WinForms, and Win32. It provides a new unified set of APIs and tools that can be used to develop desktop apps on Windows 11 (as well as downwards to Windows 10, version 1809). I decided to have a look at what this framework provides and this post is written as I am trying it. To evaluate it, I’ll try to build a small application that does conversion between Celsius and Fahrenheit degrees as you type in a field. Disclaimer: I hav ..read more
Visit website

Follow Marius Bancila's Blog on FeedSpot

Continue with Google
Continue with Apple
OR