Wednesday, 06 October 2010
My latest article, Concept Checking Without Concepts in C++ was published on the Dr Dobb's website a couple of weeks ago.
One of the important features of the now-defunct C++0x Concepts proposal was the ability to overload functions based on whether or not their arguments met certain concepts. This article describes a way to allow that for concepts based on the presence of particular member functions.
The basic idea is that you can write traits classes that detect
particular sets of member functions. Function overloads that require
these concepts can then be enabled or disabled by
std::enable_if with these traits.
The example I use is checking for a Lockable type which
try_lock() member functions, but the same technique
could easily be used for other concepts that required other member
Read the article for the full details.