'How about the performance of std::distance for std::list?

list<int> l = { 1,2,3 };
auto iter1 = l.begin();
std::advance(iter1, 1);
auto iter2 = l.end();
std::advance(iter2, -1);
auto dist = std::distance(iter1, iter2);

cout << dist << endl;

I just wonder if std::distance(iter1, iter2) is a one-time calculation or a loop to count the number.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source