What does default construction mean? Why do we write default constructors? When and why should we require them? I’ve been pondering these questions lately. One of the great things that C++ gets right is that it grants programmers the ability to create types that behave like built-in types. Many languages don’t offer this feature, treating… Continue reading Thoughts on Default Construction
Here’s an exercise: given a nice piece of code sitting in a file, how do you take that code and make it generic, in the style of an STL algorithm? For our example, let’s consider an algorithm that isn’t (yet) in the STL. First, the problem it solves. Imagine that you have a set (in… Continue reading Development of an Algorithm
C++17 introduces class template deduction: a way for the compiler to deduce the arguments to construct a class template without our having to write a make_* function. But it’s not quite as straightforward as it seems. Imagine we have a simple type that will tell us when it’s copied or moved, just for testing. struct… Continue reading C++17 Class Templates: Deduced or Not?
C++Now 2017 just wrapped up in Aspen, CO. A great week of presentations and discussions once more. C++Now is a very different conference from the normal mainstream. For a start, it’s small – only 150 people. And the sort of content you find at C++Now is more niche material: challenging the status quo and trying… Continue reading C++Now 2017 – Report
Being a quick sketch combining <chrono> and <random> functionality, with cryptarithmetic interludes… At CppCon this year there were several good talks about randomness and time calculations in C++. On randomness: Walter Brown’s What C++ Programmers Need to Know About Header <random> and Cheinan Marks’ I Just Wanted a Random Integer! were both excellent talks. And… Continue reading CHRONO + RANDOM = ?
One of the things I like to do in my spare time is study the STL algorithms. It is easy to take them for granted and easy, perhaps, to imagine that they are mostly trivial. And some are: I would think that any decent interview candidate ought to be able to write find correctly. (Although… Continue reading An algorithmic sketch: inplace_merge
(Resulting from my claim that “a child of 8 can understand monoids…”) Wikipedia says: “In abstract algebra, a branch of mathematics, a monoid is an algebraic structure with a single associative binary operation and an identity element.” Wolfram says: A monoid is a set that is closed under an associative binary operation and has an… Continue reading ELI5: monoids
OK, more than one person wanted explanations of The C++ <random> Lame List, so here are some of my thoughts, if only to save people searching elsewhere. Calling rand() is lame because it’s an LCG with horrible randomness properties, and we can do better. And if you’re not calling rand(), there’s no reason to call… Continue reading Lameness Explained
Network programmers of a certain age may remember the Windows Sockets Lame List. I previously wrote a short “don’t-do-that-do-this” guide for modern C++ randomness, and I was recently reading another Reddit exchange featuring STL, author of many parts of Microsoft’s STL implementation, when it struck me that use of C++ <random> needs its own lame… Continue reading The C++
<random> Lame List
When I was young, I read lots of books with titles (or at least subheadings) along the lines of, “Amaze Your Friends and Confound Your Enemies” – a lot of them were filled with tricks and oddities like the Birthday Paradox, or the old saw about the elephant from Denmark. It turns out that if… Continue reading Amaze your friends, and confound your enemies!