The Evolution of Functions in Modern C++

In programming, a function is a block of code that performs a computational task. (In practice, people write functions that perform many tasks, which is not very good, but it’s a topic beyond the purpose of this article). Functions are a fundamental concept of programming languages and C++ makes no exception. In fact, in C++ there is a large variety of functions that has evolved over time. In this article, I will give a brief walkthrough of this evolution starting with C++11. Since there are many things to talk about, I will not get into too many details on these topics but will provide various links for you to follow if you want to learn more.

Use Cases of Variable Templates in C++

Since C++14 variables can also be templatized. A variable template defines a family of variable (when declared at namespace scope) or a family of static data members (when defined at class scope). The question is, what is the benefit of variable templates?

Initializing statement for if/switch/foreach

There are several statements in C++ whose syntax was modified in recent versions of the standard. I refer here to the if and switch statements that were modified in C++17 to include initializing statements, and the range-based for loop that supports the same as of C++20. Their general form is shown in the following table:

moneycpp – a C++ library for handling monetary values

I have been working lately on a C++ library for handling monetary values, currencies, rounding and other related features. It is called moneycpp and it’s a C++ 17 header-only, cross-platform library available on GitHub.

The library is intended for being used in a variety of types of application including ERP systems, banking, finance, insurance, games, and others.

The following is a list of its core requirements:

C++17 removed and deprecated features

Along with the new features added to the language and the standard library in C++17, there are also existing features that have been either removed (after being deprecated in a previous version) or deprecated so they would be removed sometime in the future. Although not complete, the following tables list the most important of these removed or deprecated features.

Transform and reduce alternatives

Transform-reduce is a pattern in which a set of data is first modified by applying a transformation on each of the elements and then it is reduced to a single value. In C++, this can be implemented straightforwardly with std::transform and std::accumulate. In C++17, an alternative for std::accumulate is available; std::reduce sums a range of elements just like std::accumulate, except that it does so out of order. That means you cannot use it with operators that are not communicative or associative (including overloads of operator+ that don’t exhibit these properties). On the other hand, there is yet another algorithm called std::transform_reduce that applies a functor to all the elements of a range and then reduces them, all in an out of order manner. And then, there are also parallel versions of these algorithms. In this post, I will try to compare the performance of these possible alternatives for implementing transform-reduce.

C++17 New Rules For auto Deduction From braced-init-list

Initialization of variables in C++ can have several forms: default initialization: std::string s; value initialization: std::string s{}; direct initialization: std::string s(“demo”); copy initialization: std::string s = “demo”; list initialization: std::string s{‘d’, ‘e’, ‘m’, ‘o’}; aggregate initialization: char s[5] = {‘d’, ‘e’, ‘m’, ‘o’}; reference initialization: char& c = s[0]; C++11 introduced a generalized syntax for…

New standard library features in Visual C++ 2017 RC

The new Visual C++ 2017, currently in release candidate phase, provides a series of updates and fixes to both the C++ compiler and the standard library. A comprehensive list of these improvements is available at What’s New for Visual C++ in Visual Studio 2017 RC. In this article, I want to shortly look at the…

C++17 standard a major… disappointment

C++17 was supposed to be a major update of the C++ ISO standard. After the Jacksonville meeting (29.02 – 05.03) it looks like it’s rather going to be a major disappointment. I’m not trying to downplay the things that have been voted into the C++17 standard so far, but all major features we hoped for…