Tag Archives: C++11

Using std::chrono

The goal of this post is to show how the <chrono> library can be used to solve a practical but not that obvious problem. There is a lot of good material in the Internet where one can learn <chrono> from, … Continue reading

Posted in programming | Tagged , , | 12 Comments

String literals make bad ranges

C++20 will come with what we call “Ranges” library. Meanwhile, range interface has been supported ever since C++11 in one context: range-based for loop. A range-based for loop can detect anything that is a range and work with it. In … Continue reading

Posted in programming | Tagged , , , | 3 Comments

String’s competing constructors

Let’s start with the problem. I want to check whether a program received a text message that consists of four consecutive zeroes. Not ‘0’, but the numeric zero. I will create a constant std::string representing the special sequence and compare … Continue reading

Posted in programming | Tagged , , , , | 20 Comments

A friendly type predicate

This is a sequel to the previous post on writing a custom type predicate. One of the readers on Reddit made a very insightful observation. The user has implemented a type that she intends to use with our library, call … Continue reading

Posted in programming | Tagged , , , , , | 1 Comment

Your own type predicate

In this post we will see how to define a type trait or a type predicate or a meta-function that would allow us to check at compile time whether a type exposes an interface that we need. That is, we … Continue reading

Posted in programming | Tagged , , , , , , | 19 Comments

error codes — some clarifications

In this post I would like to discuss two issues brought up by the readers regarding previous posts on using <system_error>: Storing 0 in error codes, and using non-0 success values. Concerns about using globals.

Posted in programming | Tagged , , | 4 Comments

Using error codes effectively

In the previous posts we have seen what error codes and error conditions are. But the way we used them is far from optimum. In particular, the implementation of FailureSourceCategory::equivalent was huge and error category FailureSourceCategory was forced to be … Continue reading

Posted in programming | Tagged , | 31 Comments

Your own error condition

In the previous post we have seen how you can create your own error-code enumeration for representing different reasons for failure in your component, and how you can store them and convey them type erased via std::error_code. In this post … Continue reading

Posted in programming | Tagged , | 25 Comments

Your own error code

I was recently implementing the “classification of error conditions” in my application offered by the functionality behind std::error_code. In this post I want to share some of my experience and insight. C++11 comes with a quite sophisticated mechanism for classifying … Continue reading

Posted in programming | Tagged , | 27 Comments