I am writing a function that determines whether a string contains only alphanumeric characters and spaces. I am effectively testing whether it matches the regular expression
And looking forward to C++0x, you'll be able to use lambda functions (you can try this out with gcc 4.5 or VS2010):
bool string_is_valid(const std::string &str) { return find_if(str.begin(), str.end(), [](char c) { return !(isalnum(c) || (c == ' ')); }) == str.end(); }