Monthly Archives: September 2009

Designing for testability: factories

When we approach the process of designing our software, there are many issues we must address in order to be successful. One of these issues (and you are free to disagree) is: How will we be able to test (or debug) our hand crafted piece of code?

This post will attempt to at least provide one way of writing code that is a little easier to debug and test, by making use of the factory design pattern.

Continue reading Designing for testability: factories

Substitution failure is not an error, part I

Explanation on what is SFINAE can be found at wikipedia. I’ve tried to write my own explanation but ended up with the conclusion that it’s best described there, and I wouldn’t want to copy&paste stuff. If you have any question marks floating around your heads, please don’t hesitate to ask.

SFINAE is used a lot in meta-programming. For example, you will be able to find many constructs in boost that are making use of this idea.

I’ve come across a pretty nice and complex use of SFINAE on stackoverflow the other day. The code below generates a templated class HasX, whose member HasX::value denotes whether the class T has a member (data or function) called x, or not. Let me introduce the code, and an explanation will follow.

Continue reading Substitution failure is not an error, part I