{"action":"created","issue":{"url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/1687","labels_url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/1687/labels{/name}","comments_url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/1687/comments","events_url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/1687/events","html_url":"https://github.com/Project-OSRM/osrm-backend/pull/1687","id":106447291,"number":1687,"title":"Caches iterators instead of invoking function calls on every iteration.","user":{"login":"daniel-j-h","id":527241,"avatar_url":"https://avatars.githubusercontent.com/u/527241?v=3","gravatar_id":"","url":"https://api.github.com/users/daniel-j-h","html_url":"https://github.com/daniel-j-h","followers_url":"https://api.github.com/users/daniel-j-h/followers","following_url":"https://api.github.com/users/daniel-j-h/following{/other_user}","gists_url":"https://api.github.com/users/daniel-j-h/gists{/gist_id}","starred_url":"https://api.github.com/users/daniel-j-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniel-j-h/subscriptions","organizations_url":"https://api.github.com/users/daniel-j-h/orgs","repos_url":"https://api.github.com/users/daniel-j-h/repos","events_url":"https://api.github.com/users/daniel-j-h/events{/privacy}","received_events_url":"https://api.github.com/users/daniel-j-h/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-14T23:26:26Z","updated_at":"2015-09-15T10:11:21Z","closed_at":"2015-09-15T10:11:21Z","pull_request":{"url":"https://api.github.com/repos/Project-OSRM/osrm-backend/pulls/1687","html_url":"https://github.com/Project-OSRM/osrm-backend/pull/1687","diff_url":"https://github.com/Project-OSRM/osrm-backend/pull/1687.diff","patch_url":"https://github.com/Project-OSRM/osrm-backend/pull/1687.patch"},"body":"This caches iterators, i.e. especially the end iterator when possible.\r\n\r\nThe problem:\r\n\r\n    for (auto it = begin(seq); it != end(seq); ++it)\r\n\r\nthis has to call `end(seq)` on every iteration, since the compiler is\r\nnot able to reason about the call's site effects (too bad, huh).\r\n\r\nInstead do it like this:\r\n\r\n    for (auto it = begin(seq), end = end(seq); it != end; ++it)\r\n\r\ncaching the end iterator.\r\n\r\nOf course, still better would be:\r\n\r\n    for (auto&& each : seq)\r\n\r\nif all you want is to capture the value (not the iterator).\r\n\r\nAnd still better: use algorithms that express intend, like `std::count_if`, `std::accumulate`, and so on. Hand-written loops are the root of all evil!\r\n\r\nWhy `auto&&` you may ask? Because it binds to everything and never copies!\r\n\r\nSkim the referenced proposal (that was rejected, but nevertheless) for a\r\ndetailed explanation on range-based for loops and why `auto&&` is great.\r\n\r\nReference:\r\n\r\n- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3853.htm"},"comment":{"url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/comments/140344448","html_url":"https://github.com/Project-OSRM/osrm-backend/pull/1687#issuecomment-140344448","issue_url":"https://api.github.com/repos/Project-OSRM/osrm-backend/issues/1687","id":140344448,"user":{"login":"daniel-j-h","id":527241,"avatar_url":"https://avatars.githubusercontent.com/u/527241?v=3","gravatar_id":"","url":"https://api.github.com/users/daniel-j-h","html_url":"https://github.com/daniel-j-h","followers_url":"https://api.github.com/users/daniel-j-h/followers","following_url":"https://api.github.com/users/daniel-j-h/following{/other_user}","gists_url":"https://api.github.com/users/daniel-j-h/gists{/gist_id}","starred_url":"https://api.github.com/users/daniel-j-h/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daniel-j-h/subscriptions","organizations_url":"https://api.github.com/users/daniel-j-h/orgs","repos_url":"https://api.github.com/users/daniel-j-h/repos","events_url":"https://api.github.com/users/daniel-j-h/events{/privacy}","received_events_url":"https://api.github.com/users/daniel-j-h/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T10:11:21Z","updated_at":"2015-09-15T10:11:21Z","body":"Did a rebase followed by a fast-forward merge. Done!"}}