Tag Archives: stating intentions

Contracts, Preconditions & Invariants

In this post we will see what a contract is, how preconditions and invariants can be derived from the contract, and how this process can help detect bugs. Two points that I will be stressing in this post are: (1) … Continue reading

Posted in programming | Tagged , , | 3 Comments

Semantic requirements in concepts

The word ‘concept’ in the context of C++ generic programming has two meanings. The first is more abstract: it is the notion from the domain of Generic Programming (GP) in general. GP is not tied to any specific language: it … Continue reading

Posted in programming | Tagged , , , | 8 Comments

Deducing your intentions

The language feature in C++17 known as class template argument deduction was intended to supersede factory functions like make_pair, make_tuple, make_optional, as described in p0091r2. This goal has not been fully achieved and we may still need to stick to … Continue reading

Posted in programming | Tagged , , | 14 Comments

Faces of undefined behavior

I have been busy recently (doing C++-related stuff) and cannot find a spare time for preparing a decent blog post. I expect that to change in November. For the interim I am posting here my last year’s talk at code::dive: … Continue reading

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

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

Help the compiler warn you

Compiler warnings are a very useful tool for detecting bugs in your program. Because you can enable them selectively, and because you can choose to turn them into hard errors on your compiler, you can in fact build a dialect, … Continue reading

Posted in programming | Tagged , , , | 8 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

Asserts in constexpr functions

Assertions (like C-style macro assert) are not an ideal, but still useful tool for indicating assumptions about program correctness, and help finding programmer bugs. In this post we will see how we can use assertions in constexpr functions. This works … Continue reading

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

Toggles in functions

Have you ever seen a function call like this? We are processing something: this should be clear from the context. But what do these parameters mean? What is true and what is false? From the function call we will never … Continue reading

Posted in programming | Tagged , , | 40 Comments