Archive for the ‘snippets’ Category
ScopeLogger
Posted on: 18/11/2009
- In: snippets
- 13 Comments
The RAII design pattern can be utilized to create simple and intuitive logging facilities, like the one we will present now. Through the useful macro LOG_FUNC, the proposed ScopeLogger will easily create function call graphs at run time, to allow easy debugging and tracking of program execution.
One-line rsort of an integer array
Posted on: 03/10/2009
Suppose you have an array of integers and a comparator function object. We would like to have the array sorted in a reverse order.. Using only one line of code.
Portable measurement of execution time
Posted on: 19/08/2009
- In: snippets
- 2 Comments
Once in a while so it happens that a programmer wishes to time his own creation. This article presents a simple and portable implementation of a Timer class which saves the time of its creation and computes the time it took until destruction, effectively measuring the runtime spent in the enclosing scope.
The classes istringstream & ostringstream can be utilized to create generic, templated, toString() & fromString() functions. This functionality (which is built-in in many languages, such as Java) may come in very handy, quite often.
Printing using std::copy
Posted on: 14/08/2009
From time to time we are required to print out a vector. It is possible to utilize the standard copy algorithm (std::copy) to do just that.
Recent comments