Fix an incorrect use of iterator.

This change uses index instead of iterator to access elements in
`all_targets` to avoid using invalidated iterator after insertion.

MSVC 2019 reports "cannot increment value-initialized deque iterator".
And C++ standard says "an insertion at either end of the deque
invalidates all the iterators to the deque".

Bug: webrtc:11255
Change-Id: I2167bfe875bb0059e81eba334bbd6921e287d6d9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176101
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31354}
diff --git a/rtc_base/thread.cc b/rtc_base/thread.cc
index 5e48e4b..f8e299a 100644
--- a/rtc_base/thread.cc
+++ b/rtc_base/thread.cc
@@ -168,8 +168,8 @@
   // We check the pre-existing who-sends-to-who graph for any path from target
   // to source. This loop is guaranteed to terminate because per the send graph
   // invariant, there are no cycles in the graph.
-  for (auto it = all_targets.begin(); it != all_targets.end(); ++it) {
-    const auto& targets = send_graph_[*it];
+  for (size_t i = 0; i < all_targets.size(); i++) {
+    const auto& targets = send_graph_[all_targets[i]];
     all_targets.insert(all_targets.end(), targets.begin(), targets.end());
   }
   RTC_CHECK_EQ(absl::c_count(all_targets, source), 0)