Tag Archives: resource handling

Class invariants

The primary motivation for defining a class in C++ is to reflect and maintain a class invariant. In this post we will see what class invariants are and how you deal with them. Class invariants are important part of C++, … Continue reading

Posted in programming | Tagged , , , | 1 Comment

A moved-from optional

This post is in response to claims, that I have heard number of times, that the semantics of optional’s move operations are wrong: Some people are surprised that the second assert holds: the unfulfilled expectation is that moving from an … Continue reading

Posted in programming | Tagged , , , | 2 Comments

Operation cancelling and std::fstream

In the previous post we have sketched out the view that error handling is about expressing the success dependency between operations. I have also indicated the guideline “destructors only for releasing resources”. In this post we are going to see … Continue reading

Posted in programming | Tagged , , , | 11 Comments

Handling errors is canceling operations

I actually covered this topic before, in this post, but given my recent experience I feel it needs reiterating and a bit of restructuring. It boils down to the observation that any error handling I have encountered — be it … Continue reading

Posted in programming | Tagged , , , | 7 Comments

Rvalues redefined

In this post we will explore what I consider the most significant language change in C++17. I call it the most significant because it changes the way you design your resource-managing types and how you think about initialization. It is … Continue reading

Posted in programming | Tagged , | 37 Comments

Sessions and object lifetimes

In this post we will see how C++ object lifetime can be used to control the duration of sessions: time spent owing and using a resource. The goal is to get a better understanding of what tools the language offers … Continue reading

Posted in programming | Tagged , , , | 6 Comments

Declaring the move constructor

Update. I have updated the post a bit, as it misled a number of people to think that you need to define the move constructor in a cpp file. This is not so. I have now also highlighted another important … Continue reading

Posted in programming | Tagged , , , | 14 Comments

Set-up and tear-down

Recently as part of program run-time performance optimization effort, I was scanning through the code for occurrences of keyword new. The goal was to find unnecessary memory allocations. I was surprised to find most of news in the unit test … Continue reading

Posted in programming | Tagged , , | 5 Comments

noexcept — what for?

In this post I would like to share my observation on where using noexcept really adds value. It is less often than what one might expect, and it does not have that much to do with throwing or not throwing … Continue reading

Posted in programming | Tagged , , , , | 43 Comments