Stupid Template Tricks - Pride and Parser Combinators, Part Two

Previously, we started work a small C++ template compiletime, parser combinator library. We covered compile time strings, parser data structures, a few basic combinators, and parsers that consume input. This time around, we'll continue to create a more complete library of compile time parser combinators. We'll take a look at…

Stupid Template Tricks - Pride and Parser Combinators, Part One

It is a truth universally acknowledged, that a template metaprogrammer in possession of a domain specific language, must be in want of a compile time parser. However much a game of compile time snake may be enjoyed by such a programmer, this truth is so well fixed, and the problem…

Stupid Template Tricks: Snake Part 2 - Interactive Nibbler

Compile time Nibbler, man. We gotta get this sucker done. Last time, we got so caught in metaprogramming that we ended up with a state machine. To play a game, you had enter all of the commands ahead of time. That's pathetic. Is that what you want to do with…

Stupid Template Tricks: Snake

Conway's game of Life may be mathematically interesting, but it is not what most people would consider a real game. So let's take a look at another product of the 70's, the arcade game Snake. This post walks through a complete, compile time implementation of a Snake game using C…

Stupid Template Tricks: Short-Circuiting

C++ templates make it remarkably easy to shoot yourself in the foot. Case in point, this seemly innocent template function: template <unsigned val> struct is_even { static const bool value = (val > 1) && (is_even<val - 2>::value); }; template <> struct is…

Stupid Template Tricks: Compile Time Pseudo-Random Number Generator

What with all those pesky NSA backdoors, runtime random number generation is just not secure. So let's build a compile time pseudo-random number generator with C++ templates. In this post, I'll walk through the implementation of a simple, deterministic pseudo-random number generator using a linear feedback shift register (LFSR). The…