auto it = vector.begin() resulting type is not convertible to const_iterator

后端 未结 3 983
予麋鹿
予麋鹿 2021-01-13 02:41

Containers are required to provide an iterator type which is implicitly convertible to a const_iterator. Given this, I am trying to use auto

3条回答
  •  感动是毒
    2021-01-13 03:11

    The problem has nothing common with the iterator conversion. The compiler simply unable to determine the template argument. It is the same if you would write

    int x = 10;
    long y = 20;
    
    std::cout << std::max( x, y ) << std::endl;
    

    though an object of type int can be implicitly converted to an object of type long.

    As for your example you could write

    const size_t n = std::distance::const_iterator> (it, itr);
    

提交回复
热议问题