Possible Duplicate:
remove_if equivalent for std::map
I have a set of strings:
set <wstring> strings;
// ...
I wish to remove strings according to a predicate, e.g.:
std::remove_if ( strings.begin(), strings.end(), []( const wstring &s ) -> bool { return s == L"matching"; });
When I attempt this, I get the following compiler error:
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\algorithm(1840): error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::basic_string<_Elem,_Traits,_Ax>'
The error appears to suggest that std::string
doesn't have a by-value copy constructor ( which would be illegal). Is it somehow bad to use std::remove_if
with std::set
? Should I be doing something else instead such as several iterations of set::find()
followed by set::erase()
?
strings.erase(L"matching");
. One presumes that your actual predicate isn't as trivial. – Trost