Rule A23-0-1 (required, implementation, automated)
An iterator shall not be implicitly converted to const_iterator.
Rationale
The Standard Template Library introduced methods for returning const iterators to containers. Making a call to these methods and immediately assigning the value they return to a const_iterator, removes implicit conversions.
Example
//% $Id: A23-0-1.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <cstdint>
#include <vector>
void Fn1(std::vector<std::int32_t>& v) noexcept
{
for (std::vector<std::int32_t>::const_iterator iter{v.cbegin()},
end{v.cend()};
iter != end;
++iter) // Compliant
{
// ...
}
}
void Fn2(std::vector<std::int32_t>& v) noexcept
{
for (auto iter{v.cbegin()}, end{v.cend()}; iter != end;
++iter) // Compliant
{
// ...
}
}
void Fn3(std::vector<std::int32_t>& v) noexcept
{
for (std::vector<std::int32_t>::const_iterator iter{v.begin()},
end{v.end()};
iter != end;
++iter) // Non-compliant
{
// ...
}
}
See also
HIC++ v4.0 [9]: 17.4.1 Use const container calls when result is immediately converted to a const iterator.