There is a std::find_first_of
but no std::find_last_of
. I want to make such a template function by myself. I consulted this code Is there a function like find_last_of in std but not in string?
But this function was compiled failed. The error seems strange, cannot convert from _FwdIt1
to _FwdIt1
. They are the same type. My compiler is visual studio 2017.
template<class _FwdIt1, class _FwdIt2>
inline _FwdIt1 find_last_of(const _FwdIt1 _First1, const _FwdIt1 _Last1,
const _FwdIt2 _First2, const _FwdIt2 _Last2)
{
return find_first_of(reverse_iterator(_Last1), reverse_iterator(_First1), _First2, _Last2); //error C2440: 'return': cannot convert from '_FwdIt1' to '_FwdIt1'
}
void test()
{
const char* s = "0123456789";
char* sb = "54";
cout<<find_last_of(s, s + strlen(s), sb, sb+strlen(sb));
}