Standard C++
A Standard-C++ approach starts with the <functional>
header, but it doesn't provide everything needed. We must or
two predicate conditions, and though SGI's STL (and hence GCC) and others provide it as an extension called "compose2", if your compiler lacks such a function then you can copy the implementation from (and read about it at) http://accu.org/index.php/journals/443.
With compose2, you can write:
#include <functional>
#include <ext/functional> // where GNU g++ hides its compose2
find_if(str.begin(), str.end(),
__gnu_cxx::compose2(
std::logical_or<bool>(),
std::ptr_fun(isalnum),
std::bind1st(std::equal_to<int>(), '_')));
It's all very logical, but verbose and slow to read.
Using the BOOST library
The leading non-Standard C++ "toolbox" library - BOOST - provides a variety of alternatives. I'll illustrate Lambda - see http://www.boost.org/doc/libs/1_44_0/doc/html/lambda.html.
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
...
find_if(str.begin(), str.end(),
bind(isalnum, boost::lambda::_1) || boost::lambda::_1 == '_');
If you prefer:
...
using namespace boost::lambda;
...
bind(isalnum, _1) || _1 == '_');
C++0x
FWIW, the next C++ Standard (due out real soon now, and already partially implemented in very recent versions of several popular compilers) will provide better inbuilt support for lambdas:
...
[](char x) { return isalnum(x) || x == '_'; });
Discussion
Given how much trouble all this is, you must be wondering whether it's best to stick to what you started with. Probably. Still, these lambda things do help if you've got a lot of places you want to use them and the predicates are different in each.