{"action":"created","comment":{"url":"https://api.github.com/repos/root-project/root/pulls/comments/148466148","pull_request_review_id":73707616,"id":148466148,"diff_hunk":"@@ -59,90 +59,159 @@ namespace Internal {\n } // namespace ROOT\n \n template <typename T>\n-class TTreeReaderArray: public ROOT::Internal::TTreeReaderArrayBase {\n+class TTreeReaderArray : public ROOT::Internal::TTreeReaderArrayBase {\n public:\n+   /// Create an array reader of branch \"branchname\" for TTreeReader \"tr\".\n+   TTreeReaderArray(TTreeReader &tr, const char *branchname)\n+      : TTreeReaderArrayBase(&tr, branchname, TDictionary::GetDictionary(typeid(T))) {}\n+\n+   T &At(std::size_t idx) { return *static_cast<T *>(UntypedAt(idx)); }\n+   const T &At(std::size_t idx) const { return *static_cast<T *>(UntypedAt(idx)); }\n+   T &operator[](std::size_t idx) { return At(idx); }\n+   const T &operator[](std::size_t idx) const { return At(idx); }\n+\n+   /// Random access iterator to the elements of a TTreeReaderArray\n+   class Iterator_t : public std::iterator<std::random_access_iterator_tag, T> {\n+      TTreeReaderArray *fArray; ///< The array iterated over; nullptr if invalid/past-the-end.\n+      std::size_t fIndex;       ///< Current index in the array.\n+      std::size_t fSize;        ///< Size of the TTreeReaderArray\n+   public:\n+      /// Default ctor: constructs a past-the-end iterator\n+      Iterator_t() : fArray(nullptr), fIndex(0u), fSize(0u) {}\n+\n+      /// Construct iterator\n+      Iterator_t(std::size_t index, TTreeReaderArray *array)\n+         : fArray(array), fIndex(index), fSize(fArray ? fArray->GetSize() : 0u)\n+      {\n+         if (fIndex >= fSize)\n+            fArray = nullptr; // invalidate iterator\n+      }\n \n-   // Iterator through the indices of a TTreeReaderArray.\n-   struct Iterator_t:\n-      public std::iterator<std::input_iterator_tag, T, long> {\n-      // Default initialized, past-end iterator.\n-      Iterator_t() :\n-         fIndex(0), fArray(0) {}\n+      /// Construct iterator from a const TTreeReaderArray\n+      Iterator_t(std::size_t index, const TTreeReaderArray *array)\n+         : Iterator_t(index, const_cast<TTreeReaderArray *>(array)) {}\n \n-      // Initialize with an array and index.\n-      Iterator_t(size_t idx, TTreeReaderArray* array) :\n-         fIndex(idx), fArray(array) {}\n+      Iterator_t(Iterator_t &&) = default;\n+      Iterator_t(const Iterator_t &) = default;\n+      Iterator_t &operator=(Iterator_t &&) = default;\n+      Iterator_t &operator=(const Iterator_t &) = default;\n \n-      size_t fIndex; // Current index in the array.\n-      TTreeReaderArray* fArray; // The array iterated over; 0 if invalid / end.\n+      T &operator*()\n+      {\n+         R__ASSERT(fArray && \"invalid iterator!\");\n+         return fArray->At(fIndex);\n+      }\n \n-      bool IsValid() const { return fArray; }\n+      const T &operator*() const\n+      {\n+         R__ASSERT(fArray && \"invalid iterator!\");\n+         return fArray->At(fIndex);\n+      }\n+\n+      T *operator->() { return IsValid() ? &fArray->At(fIndex) : nullptr; }\n \n-      bool operator==(const Iterator_t& lhs) const {\n-         // Compare two iterators as equal; follow C++14 requiring two past-end\n-         // iterators to be equal.\n-         if (!IsValid() && !lhs.IsValid())\n+      bool operator==(const Iterator_t &other) const\n+      {\n+         // Follow C++14 requiring two past-the-end iterators to be equal.\n+         if (!IsValid() && !other.IsValid())\n             return true;\n-         return fIndex == lhs.fIndex && fArray == lhs.fArray;\n+         return fArray == other.fArray && fIndex == other.fIndex;\n       }\n \n-      bool operator!=(const Iterator_t& lhs) const {\n-         // Compare not equal.\n-         return !(*this == lhs);\n+      bool operator!=(const Iterator_t &other) const { return !(*this == other); }\n+\n+      /// Pre-increment operator\n+      Iterator_t &operator++()\n+      {\n+         ++fIndex;\n+         if (fIndex >= fSize)\n+            fArray = nullptr; // invalidate iterator\n+         return *this;\n       }\n \n-      Iterator_t operator++(int) {\n-         // Post-increment (it++).\n-         Iterator_t ret = *this;\n-         this->operator++();\n+      /// Post-increment operator\n+      Iterator_t operator++(int)\n+      {\n+         auto ret = *this;\n+         auto &self = *this;\n+         ++self;","path":"tree/treeplayer/inc/TTreeReaderArray.h","position":120,"original_position":120,"commit_id":"3a3a96ad63dc93cf8e2b80cb522405cdaedb73b2","original_commit_id":"3a3a96ad63dc93cf8e2b80cb522405cdaedb73b2","user":{"login":"Axel-Naumann","id":144675,"avatar_url":"https://avatars1.githubusercontent.com/u/144675?v=4","gravatar_id":"","url":"https://api.github.com/users/Axel-Naumann","html_url":"https://github.com/Axel-Naumann","followers_url":"https://api.github.com/users/Axel-Naumann/followers","following_url":"https://api.github.com/users/Axel-Naumann/following{/other_user}","gists_url":"https://api.github.com/users/Axel-Naumann/gists{/gist_id}","starred_url":"https://api.github.com/users/Axel-Naumann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Axel-Naumann/subscriptions","organizations_url":"https://api.github.com/users/Axel-Naumann/orgs","repos_url":"https://api.github.com/users/Axel-Naumann/repos","events_url":"https://api.github.com/users/Axel-Naumann/events{/privacy}","received_events_url":"https://api.github.com/users/Axel-Naumann/received_events","type":"User","site_admin":false},"body":"You find these two lines nicer than `this->operator++()` or if need be `++(*this)`? I find the option you chose my third favorite, due to the `auto &` and the second local var that seems to be almost identical to `ret`. I.e. I find this code much more complex to grasp due to the extra degree of freedom (extra local var)... But as \"I find\" tries to say: this is really a matter of taste, so if you disagree then feel free to keep yours!","created_at":"2017-11-02T08:28:34Z","updated_at":"2017-11-02T08:43:15Z","html_url":"https://github.com/root-project/root/pull/1259#discussion_r148466148","pull_request_url":"https://api.github.com/repos/root-project/root/pulls/1259","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/root-project/root/pulls/comments/148466148"},"html":{"href":"https://github.com/root-project/root/pull/1259#discussion_r148466148"},"pull_request":{"href":"https://api.github.com/repos/root-project/root/pulls/1259"}}},"pull_request":{"url":"https://api.github.com/repos/root-project/root/pulls/1259","id":149822351,"html_url":"https://github.com/root-project/root/pull/1259","diff_url":"https://github.com/root-project/root/pull/1259.diff","patch_url":"https://github.com/root-project/root/pull/1259.patch","issue_url":"https://api.github.com/repos/root-project/root/issues/1259","number":1259,"state":"open","locked":false,"title":"Make TTreeReaderArray's iterator random access","user":{"login":"bluehood","id":10999034,"avatar_url":"https://avatars3.githubusercontent.com/u/10999034?v=4","gravatar_id":"","url":"https://api.github.com/users/bluehood","html_url":"https://github.com/bluehood","followers_url":"https://api.github.com/users/bluehood/followers","following_url":"https://api.github.com/users/bluehood/following{/other_user}","gists_url":"https://api.github.com/users/bluehood/gists{/gist_id}","starred_url":"https://api.github.com/users/bluehood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluehood/subscriptions","organizations_url":"https://api.github.com/users/bluehood/orgs","repos_url":"https://api.github.com/users/bluehood/repos","events_url":"https://api.github.com/users/bluehood/events{/privacy}","received_events_url":"https://api.github.com/users/bluehood/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-10-31T15:37:48Z","updated_at":"2017-11-02T08:43:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ddc48e9dae6334433a3d059043dacf06890f9e2c","assignee":{"login":"bluehood","id":10999034,"avatar_url":"https://avatars3.githubusercontent.com/u/10999034?v=4","gravatar_id":"","url":"https://api.github.com/users/bluehood","html_url":"https://github.com/bluehood","followers_url":"https://api.github.com/users/bluehood/followers","following_url":"https://api.github.com/users/bluehood/following{/other_user}","gists_url":"https://api.github.com/users/bluehood/gists{/gist_id}","starred_url":"https://api.github.com/users/bluehood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluehood/subscriptions","organizations_url":"https://api.github.com/users/bluehood/orgs","repos_url":"https://api.github.com/users/bluehood/repos","events_url":"https://api.github.com/users/bluehood/events{/privacy}","received_events_url":"https://api.github.com/users/bluehood/received_events","type":"User","site_admin":false},"assignees":[{"login":"bluehood","id":10999034,"avatar_url":"https://avatars3.githubusercontent.com/u/10999034?v=4","gravatar_id":"","url":"https://api.github.com/users/bluehood","html_url":"https://github.com/bluehood","followers_url":"https://api.github.com/users/bluehood/followers","following_url":"https://api.github.com/users/bluehood/following{/other_user}","gists_url":"https://api.github.com/users/bluehood/gists{/gist_id}","starred_url":"https://api.github.com/users/bluehood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluehood/subscriptions","organizations_url":"https://api.github.com/users/bluehood/orgs","repos_url":"https://api.github.com/users/bluehood/repos","events_url":"https://api.github.com/users/bluehood/events{/privacy}","received_events_url":"https://api.github.com/users/bluehood/received_events","type":"User","site_admin":false}],"requested_reviewers":[{"login":"pcanal","id":5175087,"avatar_url":"https://avatars3.githubusercontent.com/u/5175087?v=4","gravatar_id":"","url":"https://api.github.com/users/pcanal","html_url":"https://github.com/pcanal","followers_url":"https://api.github.com/users/pcanal/followers","following_url":"https://api.github.com/users/pcanal/following{/other_user}","gists_url":"https://api.github.com/users/pcanal/gists{/gist_id}","starred_url":"https://api.github.com/users/pcanal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcanal/subscriptions","organizations_url":"https://api.github.com/users/pcanal/orgs","repos_url":"https://api.github.com/users/pcanal/repos","events_url":"https://api.github.com/users/pcanal/events{/privacy}","received_events_url":"https://api.github.com/users/pcanal/received_events","type":"User","site_admin":false},{"login":"dpiparo","id":7850302,"avatar_url":"https://avatars2.githubusercontent.com/u/7850302?v=4","gravatar_id":"","url":"https://api.github.com/users/dpiparo","html_url":"https://github.com/dpiparo","followers_url":"https://api.github.com/users/dpiparo/followers","following_url":"https://api.github.com/users/dpiparo/following{/other_user}","gists_url":"https://api.github.com/users/dpiparo/gists{/gist_id}","starred_url":"https://api.github.com/users/dpiparo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpiparo/subscriptions","organizations_url":"https://api.github.com/users/dpiparo/orgs","repos_url":"https://api.github.com/users/dpiparo/repos","events_url":"https://api.github.com/users/dpiparo/events{/privacy}","received_events_url":"https://api.github.com/users/dpiparo/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/root-project/root/pulls/1259/commits","review_comments_url":"https://api.github.com/repos/root-project/root/pulls/1259/comments","review_comment_url":"https://api.github.com/repos/root-project/root/pulls/comments{/number}","comments_url":"https://api.github.com/repos/root-project/root/issues/1259/comments","statuses_url":"https://api.github.com/repos/root-project/root/statuses/3a3a96ad63dc93cf8e2b80cb522405cdaedb73b2","head":{"label":"bluehood:random_access_reader","ref":"random_access_reader","sha":"3a3a96ad63dc93cf8e2b80cb522405cdaedb73b2","user":{"login":"bluehood","id":10999034,"avatar_url":"https://avatars3.githubusercontent.com/u/10999034?v=4","gravatar_id":"","url":"https://api.github.com/users/bluehood","html_url":"https://github.com/bluehood","followers_url":"https://api.github.com/users/bluehood/followers","following_url":"https://api.github.com/users/bluehood/following{/other_user}","gists_url":"https://api.github.com/users/bluehood/gists{/gist_id}","starred_url":"https://api.github.com/users/bluehood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluehood/subscriptions","organizations_url":"https://api.github.com/users/bluehood/orgs","repos_url":"https://api.github.com/users/bluehood/repos","events_url":"https://api.github.com/users/bluehood/events{/privacy}","received_events_url":"https://api.github.com/users/bluehood/received_events","type":"User","site_admin":false},"repo":{"id":39002171,"name":"root","full_name":"bluehood/root","owner":{"login":"bluehood","id":10999034,"avatar_url":"https://avatars3.githubusercontent.com/u/10999034?v=4","gravatar_id":"","url":"https://api.github.com/users/bluehood","html_url":"https://github.com/bluehood","followers_url":"https://api.github.com/users/bluehood/followers","following_url":"https://api.github.com/users/bluehood/following{/other_user}","gists_url":"https://api.github.com/users/bluehood/gists{/gist_id}","starred_url":"https://api.github.com/users/bluehood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluehood/subscriptions","organizations_url":"https://api.github.com/users/bluehood/orgs","repos_url":"https://api.github.com/users/bluehood/repos","events_url":"https://api.github.com/users/bluehood/events{/privacy}","received_events_url":"https://api.github.com/users/bluehood/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bluehood/root","description":"TDataFrame development fork","fork":true,"url":"https://api.github.com/repos/bluehood/root","forks_url":"https://api.github.com/repos/bluehood/root/forks","keys_url":"https://api.github.com/repos/bluehood/root/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bluehood/root/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bluehood/root/teams","hooks_url":"https://api.github.com/repos/bluehood/root/hooks","issue_events_url":"https://api.github.com/repos/bluehood/root/issues/events{/number}","events_url":"https://api.github.com/repos/bluehood/root/events","assignees_url":"https://api.github.com/repos/bluehood/root/assignees{/user}","branches_url":"https://api.github.com/repos/bluehood/root/branches{/branch}","tags_url":"https://api.github.com/repos/bluehood/root/tags","blobs_url":"https://api.github.com/repos/bluehood/root/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bluehood/root/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bluehood/root/git/refs{/sha}","trees_url":"https://api.github.com/repos/bluehood/root/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bluehood/root/statuses/{sha}","languages_url":"https://api.github.com/repos/bluehood/root/languages","stargazers_url":"https://api.github.com/repos/bluehood/root/stargazers","contributors_url":"https://api.github.com/repos/bluehood/root/contributors","subscribers_url":"https://api.github.com/repos/bluehood/root/subscribers","subscription_url":"https://api.github.com/repos/bluehood/root/subscription","commits_url":"https://api.github.com/repos/bluehood/root/commits{/sha}","git_commits_url":"https://api.github.com/repos/bluehood/root/git/commits{/sha}","comments_url":"https://api.github.com/repos/bluehood/root/comments{/number}","issue_comment_url":"https://api.github.com/repos/bluehood/root/issues/comments{/number}","contents_url":"https://api.github.com/repos/bluehood/root/contents/{+path}","compare_url":"https://api.github.com/repos/bluehood/root/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bluehood/root/merges","archive_url":"https://api.github.com/repos/bluehood/root/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bluehood/root/downloads","issues_url":"https://api.github.com/repos/bluehood/root/issues{/number}","pulls_url":"https://api.github.com/repos/bluehood/root/pulls{/number}","milestones_url":"https://api.github.com/repos/bluehood/root/milestones{/number}","notifications_url":"https://api.github.com/repos/bluehood/root/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bluehood/root/labels{/name}","releases_url":"https://api.github.com/repos/bluehood/root/releases{/id}","deployments_url":"https://api.github.com/repos/bluehood/root/deployments","created_at":"2015-07-13T09:07:07Z","updated_at":"2017-01-28T11:12:51Z","pushed_at":"2017-11-02T05:10:42Z","git_url":"git://github.com/bluehood/root.git","ssh_url":"git@github.com:bluehood/root.git","clone_url":"https://github.com/bluehood/root.git","svn_url":"https://github.com/bluehood/root","homepage":"http://root.cern.ch","size":632061,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"root-project:master","ref":"master","sha":"0a90400ba14ba4ba073d351194f9e3802be64d39","user":{"login":"root-project","id":6450093,"avatar_url":"https://avatars1.githubusercontent.com/u/6450093?v=4","gravatar_id":"","url":"https://api.github.com/users/root-project","html_url":"https://github.com/root-project","followers_url":"https://api.github.com/users/root-project/followers","following_url":"https://api.github.com/users/root-project/following{/other_user}","gists_url":"https://api.github.com/users/root-project/gists{/gist_id}","starred_url":"https://api.github.com/users/root-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/root-project/subscriptions","organizations_url":"https://api.github.com/users/root-project/orgs","repos_url":"https://api.github.com/users/root-project/repos","events_url":"https://api.github.com/users/root-project/events{/privacy}","received_events_url":"https://api.github.com/users/root-project/received_events","type":"Organization","site_admin":false},"repo":{"id":10994345,"name":"root","full_name":"root-project/root","owner":{"login":"root-project","id":6450093,"avatar_url":"https://avatars1.githubusercontent.com/u/6450093?v=4","gravatar_id":"","url":"https://api.github.com/users/root-project","html_url":"https://github.com/root-project","followers_url":"https://api.github.com/users/root-project/followers","following_url":"https://api.github.com/users/root-project/following{/other_user}","gists_url":"https://api.github.com/users/root-project/gists{/gist_id}","starred_url":"https://api.github.com/users/root-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/root-project/subscriptions","organizations_url":"https://api.github.com/users/root-project/orgs","repos_url":"https://api.github.com/users/root-project/repos","events_url":"https://api.github.com/users/root-project/events{/privacy}","received_events_url":"https://api.github.com/users/root-project/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/root-project/root","description":"The official ROOT repository","fork":false,"url":"https://api.github.com/repos/root-project/root","forks_url":"https://api.github.com/repos/root-project/root/forks","keys_url":"https://api.github.com/repos/root-project/root/keys{/key_id}","collaborators_url":"https://api.github.com/repos/root-project/root/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/root-project/root/teams","hooks_url":"https://api.github.com/repos/root-project/root/hooks","issue_events_url":"https://api.github.com/repos/root-project/root/issues/events{/number}","events_url":"https://api.github.com/repos/root-project/root/events","assignees_url":"https://api.github.com/repos/root-project/root/assignees{/user}","branches_url":"https://api.github.com/repos/root-project/root/branches{/branch}","tags_url":"https://api.github.com/repos/root-project/root/tags","blobs_url":"https://api.github.com/repos/root-project/root/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/root-project/root/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/root-project/root/git/refs{/sha}","trees_url":"https://api.github.com/repos/root-project/root/git/trees{/sha}","statuses_url":"https://api.github.com/repos/root-project/root/statuses/{sha}","languages_url":"https://api.github.com/repos/root-project/root/languages","stargazers_url":"https://api.github.com/repos/root-project/root/stargazers","contributors_url":"https://api.github.com/repos/root-project/root/contributors","subscribers_url":"https://api.github.com/repos/root-project/root/subscribers","subscription_url":"https://api.github.com/repos/root-project/root/subscription","commits_url":"https://api.github.com/repos/root-project/root/commits{/sha}","git_commits_url":"https://api.github.com/repos/root-project/root/git/commits{/sha}","comments_url":"https://api.github.com/repos/root-project/root/comments{/number}","issue_comment_url":"https://api.github.com/repos/root-project/root/issues/comments{/number}","contents_url":"https://api.github.com/repos/root-project/root/contents/{+path}","compare_url":"https://api.github.com/repos/root-project/root/compare/{base}...{head}","merges_url":"https://api.github.com/repos/root-project/root/merges","archive_url":"https://api.github.com/repos/root-project/root/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/root-project/root/downloads","issues_url":"https://api.github.com/repos/root-project/root/issues{/number}","pulls_url":"https://api.github.com/repos/root-project/root/pulls{/number}","milestones_url":"https://api.github.com/repos/root-project/root/milestones{/number}","notifications_url":"https://api.github.com/repos/root-project/root/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/root-project/root/labels{/name}","releases_url":"https://api.github.com/repos/root-project/root/releases{/id}","deployments_url":"https://api.github.com/repos/root-project/root/deployments","created_at":"2013-06-27T10:46:59Z","updated_at":"2017-11-01T20:16:14Z","pushed_at":"2017-11-02T08:06:19Z","git_url":"git://github.com/root-project/root.git","ssh_url":"git@github.com:root-project/root.git","clone_url":"https://github.com/root-project/root.git","svn_url":"https://github.com/root-project/root","homepage":"","size":665654,"stargazers_count":422,"watchers_count":422,"language":"C++","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":308,"mirror_url":null,"archived":false,"open_issues_count":55,"forks":308,"open_issues":55,"watchers":422,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/root-project/root/pulls/1259"},"html":{"href":"https://github.com/root-project/root/pull/1259"},"issue":{"href":"https://api.github.com/repos/root-project/root/issues/1259"},"comments":{"href":"https://api.github.com/repos/root-project/root/issues/1259/comments"},"review_comments":{"href":"https://api.github.com/repos/root-project/root/pulls/1259/comments"},"review_comment":{"href":"https://api.github.com/repos/root-project/root/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/root-project/root/pulls/1259/commits"},"statuses":{"href":"https://api.github.com/repos/root-project/root/statuses/3a3a96ad63dc93cf8e2b80cb522405cdaedb73b2"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"Axel-Naumann"}}