Skip to main content


Showing posts from December, 2006

Counted Method Chaining

I built a fun set of classes using C++ template meta-programming technique to count the number of times a member method of a class is invoked in a chain. These template classes implement a meta-programming technique called Counted Method Chaining. It counts the number of times a member function is called at compile-time and does not let programmer invoke it more than a used defiend limit. The limit is passed as a integer template parameter to the class to which to method belongs. It gives a compile time error only when method chaining is used. Otherwise it throws and exception. These set of classes use the C++ technique of co-variant return types.

/// @brief A genereral case of the template where add function
/// is public and therefore, it can be invoked.
template <unsigned int C>
class Base : public Base <C-1>
virtual Base <C-1> & add (void const *, size_t length) = 0;

/// @brief The special case of the template when C (count) becomes zero.
/// …