KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have always wondered why you cannot use locally defined classes as predicates to STL algorithms. In the question: Approaching STL algorithms, lambda, local classes and other approaches , BubbaT mentions says that ' Since the C++ standard forbids local types to be used as arguments ' Example code: int main() { int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::vector<int> v( array, array+10 ); struct even : public std::unary_function<int,bool> { bool operator()( int x ) { return !( x % 2 ); } }; std::remove_if( v.begin(), v.end(), even() ); // error } Does anyone know where in the standard is the restriction? What is the rationale for disallowing local types? EDIT : Since C++11, it is legal to use a local type as a template argument.
Tags (comma-separated)
Save Edits
Cancel