Recently me and colleague had a discussion about the following piece of code (simple bool function that checks if string is a number, +1000
not allowed, -1000
, 1234
... allowed).
He felt that it was hackish, while I thought it was nice, clean and elegant (since it uses STL, not hand made loops).
So is this a judgement call or one of us is wrong? Is this code elegant or hack?
bool validate(const std::string& m)
{
if (m.empty())
return false;
return m.end() == find_if(*m.begin() == '-'? ++m.begin() : m.begin(),
m.end(), not1(ptr_fun(isdigit)));
}