title: Determine if a string contains only alphanumeric characters (or a space)
body: <p>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 <code>^[[:alnum:] ]+$</code> but without using regular expressions. This is what I have so far:</p>
  
  <pre><code>#include &lt;algorithm&gt;
  
  static inline bool is_not_alnum_space(char c)
  {
      return !(isalpha(c) || isdigit(c) || (c == ' '));
  }
  
  bool string_is_valid(const std::string &amp;str)
  {
      return find_if(str.begin(), str.end(), is_not_alnum_space) == str.end();
  }
  </code></pre>
  
  <p>Is there a better solution, or a &ldquo;more C++&rdquo; way to do this?</p>