Is it possible to use a local class as a predicate to std::find_if?
#include <algorithm>
struct Cont
{
char* foo()
{
struct Query
{
Query(unsigned column)
: m_column(column) {}
bool operator()(char c)
{
return ...;
}
unsigned m_column;
};
char str[] = "MY LONG LONG LONG LONG LONG SEARCH STRING";
return std::find_if(str, str+45, Query(1));
}
};
int main()
{
Cont c;
c.foo();
return 0;
}
I get the following compiler error on gcc:
error: no matching function for call to 'find_if(char [52], char*, Cont::foo()::Query)'
In C++03 this is not allowed. Local(not nested) classes cannot be template parameters. In C++11 it is allowed.
Some terminology tip:
A nested class is a class that is defined withing the scope of another class, e.g.
A local class is class defined in function scope(as in your example)