(Start at the beginning of the series – and all the source can be found in my github repo) Compile-time random number generation is quite useful. For instance, we could generate GUIDs (version 4 UUIDs): namespace cx { struct guid_t { uint32_t data1; uint16_t data2; uint16_t data3; uint64_t data4; }; template constexpr guid_t guidgen() {… Continue reading Compile-time RNG tricks
Month: October 2015
Compile-time counters, revisited
(Start at the beginning of the series – and all the source can be found in my github repo) Some time ago I read a blog post showing how to make a compile-time counter: a constexpr function that would return monotonically increasing integers. When I first read it I didn’t really take the time to… Continue reading Compile-time counters, revisited
More string hashing with C++11 constexpr
(Start at the beginning of the series – and all the source can be found in my github repo) So FNV1 was easy, and Murmur3 wasn’t too much harder; for a challenge and to see how far I could go, I decided to try to compute an MD5 string hash using C++11 constexpr. This was… Continue reading More string hashing with C++11 constexpr
C++11 compile-time string hashing
(Start at the beginning of the series – and all the source can be found in my github repo) Now that I was used to writing C++11-style constexpr, I decided to try some compile-time string hashing. It turns out that FNV1 is very easy to express in a move-down-the-string recursive style: namespace detail { constexpr… Continue reading C++11 compile-time string hashing
More constexpr floating-point computation
(Start at the beginning of the series – and all the source can be found in my github repo) In the last post, I covered my first forays into writing C++11-style constexpr floating point math functions. Once I’d done some trig functions, exp, and floor and friends, it seemed like the rest would be a… Continue reading More constexpr floating-point computation
Floating-point maths, constexpr style
(Start at the beginning of the series – and all the source can be found in my github repo) To ease into constexpr programming I decided to tackle some floating-point maths functions. Disclaimer: I’m not a mathematician and this code has not been rigorously tested for numeric stability or convergence in general. I wrote it… Continue reading Floating-point maths, constexpr style
Experimenting with constexpr
Since seeing Scott Schurr at C++Now in Aspen and hearing his talks about constexpr, it’s been on my list of things to try out, and recently I got around to it. With the release of Visual Studio 2015, Microsoft’s compiler now finally supports C++11 style constexpr (modulo some minor issues), so it’s a good time… Continue reading Experimenting with constexpr