std::mismatch compile time error
Feb 7, 2012 at 12:57pm UTC
I made some compare (case insensitive) function to be able to compare some file & folder names, since it would be logical to make params const i got compile time error.
1 2 3 4 5 6 7 8 9
bool ci_compare(const std::wstring& l, const std::wstring& r)
{
const std::locale loc("" );
std::pair< std::wstring::iterator, std::wstring::iterator > result;
result = std::mismatch(l.begin(), l.end(), r.begin(),
[&loc] (std::wstring::value_type chl, std::wstring::value_type chr)
{ return std::toupper(chl, loc) == std::toupper(chr, loc); } );
return l.end() == result.first;
}
quoted first line that has error:
error C2664: 'std::_String_iterator<_Elem,_Traits,_Alloc>::_String_iterator(const std::_String_iterator<_Elem,_Traits,_Alloc> &)' : cannot convert parameter 1 from 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' to 'const std::_String_iterator<_Elem,_Traits,_Alloc> &'
How to resolve this? Beside removing const-ness from params.
Thanks for your time.
Feb 7, 2012 at 1:08pm UTC
By using const_iterators:
std::pair< std::wstring::const_iterator, std::wstring::const_iterator > result;
Feb 7, 2012 at 1:23pm UTC
Thats it. Thanks.
Topic archived. No new replies allowed.