cplusplus.co.il

Archive for the ‘snippets’ Category

ScopeLogger

Posted on: 18/11/2009

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.

Read the rest of this entry »

Advertisements

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.

Read the rest of this entry »

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.

Read the rest of this entry »

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.

Read the rest of this entry »

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.

Read the rest of this entry »