Calling the std::equal_range() algorithm on a std::set or std::list container is silly. It's worse than O(n) complexity since std::equal_range() will internally call std::distance() and std::advance() which are both O(n) on a std::set or std::list, and they will be called O(log(n)) times, so the complexity ought to be n*log(n) which is worse than linear complexity.
Yet it compiles fine and cppcheck does not detect any issue as in this silly example:
Calling the
std::equal_range()
algorithm on astd::set
orstd::list
container is silly. It's worse thanO(n)
complexity sincestd::equal_range()
will internally callstd::distance()
andstd::advance()
which are bothO(n)
on astd::set
orstd::list
, and they will be calledO(log(n))
times, so the complexity ought to ben*log(n)
which is worse than linear complexity.Yet it compiles fine and cppcheck does not detect any issue as in this silly example:
This was with the latest cppcheck in git (SHA1 16a4449901d5401cbc2db9be93d4208ef2542844 from May 28, 2022).
At least clang-tidy-14 detects it as it says: