Code written in C++
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;
};
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;
}
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<
Does just what it says...
inline void delay(const double& d)
{
clock_t start=clock();
while( (clock()-start)
Never thought i would put something from PHP into C++.
// Returns a string with all occurrences of search in subject replaced with the given replace string.
std::string str_replace(const std::string& search, const std::string& replace, std::string subject)
{
int pos = subject.find(search, 0);
while(pos != std::string::npos)
{
subject.erase(pos, search.length());
subject.insert(pos, replace);
pos = subject.find(search, pos + replace.length());
}
return subject;
}