Condition Variables

You work in a bar, pouring pints for the locals. One of your regulars comes in; he’s looking pretty grumpy today. “Whiskey” he snaps. You put down a glass and pour. You finish pouring and he necks back the drink. “Again”, he snaps. Again, you pour and as soon as you finish he necks it. This repeats two or three more times before the grumpy man slams down the money for his tab and leaves. Congratulations, you have just taken part in a “Producer/Consumer” exchange.

Continue reading “Condition Variables”

LRU Cache Implementation

One of the problems any developer will eventually have to resolve is one of latency; specifically, being able to retrieve and process data in a timely fashion.  This issue can come in many guises but they generally manifest as needing to read data from a backing store that cannot deliver the high performance needed by the application. This can be a tricky problem to solve but the general method is to implement some form of caching. The remainder of this article will discuss one caching mechanism, called the LRU Cache.

Continue reading “LRU Cache Implementation”

C++11 r-value references

The C++03 standard treats temporary types as r-values (types only meant to go on the right hand side of an assignment expression). As such, it is only possible to bind a temporary to a const reference type. This is a somewhat arbitrary and, often, frustrating rule. The original idea was that there would be no good reason to modify a temporary; however, it turns out that there are plenty of good reasons for doing so and this arbitrary restriction was just a nuisance that served no good cause.

Continue reading “C++11 r-value references”

Meta Template Programming – where to start?

A good friend of my asked me how to get started in meta-template programming. Of course, the first thing is to know C++ and know it well. Other than that, I think my best advise is to ensure you completely understand how the C++ template generation process works. For example, if you don’t know what SFINAE stands for you’re probably not really to start writing meta-templates (of course, that doesn’t mean you are not ready to start learning).

Continue reading “Meta Template Programming – where to start?”

Set union problem

Today I had the privilege of a job interview with one of the leading companies in the online streaming music space. I’d like to think the interview went well, although I was incredibly nervous and my brain decided it was going to operate in a way that suggested it was wading through treacle; but I digress. During the interview I was asked an algorithmic question and I have to admit I was initially quite flummoxed. This post is about that question. Continue reading “Set union problem”

Template syntax mind warp!

Templates are a hugely powerful feature of C++. They allow you to do so many different and cool things. Unfortunately, templates do have a bit of a reputation for having rather nasty syntax and for the most part this reputation is quite well deserved. This little quiz shows an example of some template syntax that you’ll only rarely come across but if you don’t know about it you could literally be left scratching your head in disbelieve, convinced you’ve uncovered a compiler bug.

Continue reading “Template syntax mind warp!”