Jorden Mauro

Timer

Posted by Jorden Mauro over 2 years ago
Timer class. Starts counting when an object is instantiated, but can be reset via a call to start_timer(). Elapsed time is extracted simply by calling the object name as if it were a function (operator())
class Timer{
public:
   Timer() { start=clock(); }
   ~Timer() {}
   void start_timer() { start=clock(); }
   double operator()() const
   {
      return (static_cast(clock()-start) / 
	      static_cast(CLOCKS_PER_SEC));
   }
private:
   clock_t start;
};
Language C++ / Tagged with timer, function object

Print Container

Posted by Jorden Mauro over 2 years ago
Prints the contents of a container to the console.
template void printContainer(const C& c)
{
   typename C::const_iterator it(c.begin());
   while (it!=c.end()-1){
      std::cout<<*it++<<", ";
   }
   std::cout<<*it;
}
Language C++ / Tagged with print, container

Convert to string

Posted by Jorden Mauro over 2 years ago
In case you don't have boost and need to convert a POD to string:
template inline std::string makeString(const T& val)
{
   std::ostringstream os;
   os<
Language C++ / Tagged with string, convert

Delay Function

Posted by Jorden Mauro over 2 years ago
Does just what it says...
inline void delay(const double& d)
{    
   clock_t start=clock();
   while( (clock()-start)
Language C++ / Tagged with delay