Image for post
Image for post

In C++20 std::sort, along with other standard algorithms, becomes constexpr. That makes the following code possible.


Image for post
Image for post

There is something wrong with this code. Take some time to think about it.


An introduction to one of the awaited features of C++20: the ranges.

C++20 is coming soon, with a number of cool features, one of which is the ranges library. In this article, I aim to demonstrate the power behind the elegant syntax it brings.

Image for post
Image for post

Disclaimers

  1. The library used in the code examples is not really the C++20 ranges, it’s the ranges-v3 open-source library from Eric Niebler, which is the basis of the proposal to add ranges to the C++. It’s a header-only library compatible with C++11/14/17.
  2. The code in the article is purely experimental, doesn’t really care about the cleanness and readability.

Functional Programming in C++

Functional Programming (hereinafter FP) is one of the programming paradigms C++…


How to improve your C++ programs using functional techniques

Functional programming is a programming paradigm, unfortunately, a not so popular one. Many of you (assuming you’re anywhere near C++) probably have heard that C++ is a multiparadigm language, but do you really feel that? If not (or you didn’t even know that), I’m really glad you’re here.

OOP (Object Oriented Programming) is yet another programming paradigm, a very popular one. It’s not so popular for no reason: it has lots of advantages, most of which are just perfect from the business perspective. As a result, it’s become so popular and demanding that most C++ language courses will jump to…


42 Specific Ways to Improve Your Use of C++11 and C++14

C++11/14 was a major update over the previous C++98. This book sheds light on it in a classic, Scott Meyers way. Amazon link to the book.

Image for post
Image for post

The first chapter, Deducing Types, consists of four items that prepare a good ground for understanding the 2nd and 5th chapters about auto and move semantics, respectively.

The second chapter goes deeper into the auto, suggesting when to and not to use it. …


50 specific ways to improve your use of the Standard Template Library

Image for post
Image for post

Amazon link to the book.

If you’re an experienced C++ programmer, you’ve most probably heard the name Scott Meyers, moreover, you’ve thanked him for his brilliant books. The “Effective STL” is one of them.

If you’re new to the C++ and you were trying to understand whether this book (or STL in general) is worth checking out, stay tuned!

The Standard Template Library (STL) is the language built-in library for C++. It consists of perfectly designed and implemented utilities. I’ll go ahead and say that it’s more than a library: it’s a whole world with its philosophy and rules, a…


C++20 is coming with a bunch of cool new features, one of which I’ll shortly cover here: the std::jthread.

Image for post
Image for post

The implementation of this std::jthread is based on the already existing std::thread. It’s basically a wrapper that brings two new features to the threads: they are cooperatively interruptible and join by default. Before going deeper into these two terms, note that the std::jthread object wraps anstd::thread as a member, providing the very same public functions, which simply transfer down the calls. This enables us to change any std::thread into std::jthread, knowing for sure that it’ll work as before.

The jthread is cooperatively interruptible

The name suggests…


From finate binary sequences to Fibonacci, and even further…

Once a friend of mine shared with me a logic question he was asked at an interview. It turned out to be very interesting, thus I want to share it with you, as well as our jurney to its solution.

Image for post
Image for post

The question

The problem statement goes like this:

For a given natural N count the number of N sized binary sequences with no consecutive ones.

Let’s look at the example of N=3. There are 8 binary sequences of length 3 in total:

000  OK
001 OK
010 OK
011 VIOLATING
100 OK
101 OK
110 VIOLATING
111 VIOLATING

… 3 of which…


Bugs are our enemies. Most of them are stupid and easy-to-find: an exception, a segmentation fault, an obvious memory overhead, etc. They show themselves quite soon. But there are some, that are very well hidden, like silent killers, harming unnoticeably. These are the worst ones: they’re hard to find, even harder to notice. Usually, they are noticed and fixed so late, that their damage is irreversible.

Image for post
Image for post

Let’s take a look at the following example.

This article contains gist embeds, which might not be shown in the mobile app.

The code

Consider such a situation: you have Employee objects and you want to…


Introduction to the std::thread, multithreading and a bit more

Historically, multithreading was a big pain for C++ programmers, because it wasn’t supported by the language for a long time. It was not until C++11 that it became a standard. And now “multithreading” is easier than ever. Or is it?

Image for post
Image for post

The short answer is: “Absolutely yes, but only IF you use it correctly”. C++ tried very hard to keep its multithreading interface as minimalistic and clean as possible. To prove my point, let’s see what does the std::thread class look like. In some other languages the Thread classes are pretty big, have lot’s of member functions, which make it not…

Vanand Gasparyan

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store