I just solved a programming problem with a combination of template metaprogramming, polymorphism, and bound function objects. I suddenly feel so vindicated.
Out of curiosity, what was the problem?
I was trying to find a way to elegantly represent animations for graphical primitives, an animation being broadly defined as "a property changing over time". So a single object representing something like a square being drawn on the screen could have individual animations affecting its position, rotation, scale, color, etc. without having to create a huge mountain of classes to do it.
My solution was to define three classes, derived from a base Animator class. The first is called anim::Scalar, and it is constructed using a function object that takes a single float value as a parameter. There are two more, anim::Vector and anim::Color, which take coordinate and color arguments, respectively. Then I pump the Animators full of KeyFrame objects (templated with the type of value they animate), and cycle through those while interpolating the values (float, float vector, and color).
That probably only made like 40% sense, but you get the basic idea. Honestly I'm surprised it worked out as well as it did.
Which reminds me, I have a question: does anyone here have opinions on data serialization formats? I'm planning on storing and loading those animation objects I described as files, and I've been trying to find a compact, non-flat data representation format to use. Is there something compact and not necessarily human-readable that has a hierarchical format like XML or JSON?
Though I get the feeling human-readability is still a good idea even if it's just for program input and output.