12345678910111213141516171819202122232425262728293031323334
#ifndef whenDev_when_h #define whenDev_when_h //class credit to alex79roma class timer { private: unsigned long begTime; public: void start() { begTime = clock(); } unsigned long elapsedTime() { return ((unsigned long) clock() - begTime) / CLOCKS_PER_SEC; } bool isTimeout(unsigned long seconds) { return seconds >= elapsedTime(); } }; timer t; typedef unsigned long end; end seconds; #define when(expression)\ t.start();\ while(true) {\ if(t.elapsedTime() >= seconds) {\ break;\ }\ } #endif