I have a function like this :
template<typename Iterator>
void sort2(Iterator it,
std::function<bool(typename std::remove_pointer<
typename Iterator::iterator_type>::type,
int)> func)
{
}
int main()
{
std::vector<int> a;
sort2(a.begin(),[](int,int){return false;});
}
'main()::__lambda0' is not derived from 'std::function<bool(typename std::remove_pointer<typename Iterator::iterator_type>::type, int)>'
sort2(a.begin(),[](int,int){return false;});
^
When I change it to :
template<typename Iterator>
void sort2(Iterator it,
std::function<bool(typename std::remove_pointer<
typename vector<int>::iterator/*I change this*/::iterator_type>::type,
int)> func)
{
}
It compiles fine ...
What is wrong with the first function ?!
It seems correct ... why does it give compile errors ?
iterator::iterator_typewill be a tag type (in this case, std::random_access). You probably just wantIterator::referenceIterator::iterator_typewon't be anything - you're thinking ofstd::iterator_traits<Iterator>::iterator_category.