C++

Partial function application is the process of taking a function with a number of arguments, fixing (or binding) some of its arguments and producing a new function with a smaller number of arguments. In C++, this can be achieved with std::bind() that generates a forwarding call wrapper for a callable object, and the placeholder objects from the std::placeholders namespace that are used for binding arguments to the callable object.

Read More Partial function applications

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.

Read More C++17 removed and deprecated features

Here is my list of good reads from May: Non-Ownership and Generic Programming and Regular types, oh my! Using C++17 std::optional Error Handling and std::optional std::accumulate vs. std::reduce How to Make SFINAE Pretty – Part 1: What SFINAE Brings to Code How to Make SFINAE Pretty – Part 2: the Hidden Beauty of SFINAE How…

Read More May good reads

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.

Read More Transform and reduce alternatives

The title might be a little bit misleading because, on one hand, you might not find these things funny if you are stumbling upon them and not understanding what is going on, and, on the other hand, they are not really strange when you pay attention to what is going on. However, here is a list of five (randomly picked) C++ features that would probably get you giving a second thought to what’s going on.

Read More C++ fun strange facts

The C++ preprocessor is a text replacement tool used to transform the source code in order to produce a single text file that is then passed to the actual compiler. It has various capabilities, such as including files, conditional compilation, text macro replacement, error emitting, stringizing, or token concatenation. Often developers use the preprocessor when other alternatives are available and are more appropriate. In this article, I will show five examples of when and how you can avoid the use of the preprocessor.

Read More Five examples for avoiding the preprocessor

In a previous post, I wrote about the C++ unit-testing framework Catch2. Catch uses another library, called Clara, for parsing command line arguments. Clara is an open-source, single-header, simple, composable and easy to use parser written by the author of Catch2. In this post, I will show how you can use Clara in C++ to parse command line arguments.

Read More Parsing command line arguments in C++ with Clara