{"action":"created","comment":{"url":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/comments/40488872","id":40488872,"diff_hunk":"@@ -703,6 +703,98 @@ $(H2 $(LEGACY_LNAME2 ArrayOps, array-ops, Array Indexing and Slicing Operators O\n \tThese may be combined to implement multidimensional arrays.\n \t)\n \n+\t$(P The code example below shows a simple implementation of a\n+\t2-dimensional array with overloaded indexing and slicing operators. The\n+\texplanations of the various constructs employed are given in the\n+\tsections following.)\n+\n+-------\n+struct Array2D(E)\n+{\n+    E[] impl;\n+    int stride;\n+    int width, height;\n+\n+    this(int _width, int _height, E[] initialData = [])\n+    {\n+        impl = initialData;\n+        stride = width = _width;\n+        height = _height;\n+        impl.length = width * height;\n+    }\n+\n+    // Index a single element, e.g., arr[0, 1]\n+    ref E opIndex(int i, int j) { return impl[i + stride*j]; }\n+\n+    // Array slicing, e.g., arr[1..2, 1..2], arr[2, 0..$], arr[0..$, 1].\n+    Array2D opIndex(int[2] r1, int[2] r2)\n+    {\n+        Array2D result;\n+\n+        auto startOffset = r1[0] + r2[0]*stride;\n+        auto endOffset = r1[1] + (r2[1] - 1)*stride;\n+        result.impl = this.impl[startOffset .. endOffset];\n+\n+        result.stride = this.stride;\n+        result.width = r1[1] - r1[0];\n+        result.height = r2[1] - r2[0];\n+\n+        return result;\n+    }\n+    auto opIndex(int[2] r1, int j) { return opIndex(r1, [j, j+1]); }\n+    auto opIndex(int i, int[2] r2) { return opIndex([i, i+1], r2); }\n+\n+    // Support for `x..y` notation in slicing operator.","path":"operatoroverloading.dd","position":45,"original_position":45,"commit_id":"4faee59920bc7ec3252495a965191fc20e4c67f8","original_commit_id":"4faee59920bc7ec3252495a965191fc20e4c67f8","user":{"login":"MartinNowak","id":288976,"avatar_url":"https://avatars.githubusercontent.com/u/288976?v=3","gravatar_id":"","url":"https://api.github.com/users/MartinNowak","html_url":"https://github.com/MartinNowak","followers_url":"https://api.github.com/users/MartinNowak/followers","following_url":"https://api.github.com/users/MartinNowak/following{/other_user}","gists_url":"https://api.github.com/users/MartinNowak/gists{/gist_id}","starred_url":"https://api.github.com/users/MartinNowak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MartinNowak/subscriptions","organizations_url":"https://api.github.com/users/MartinNowak/orgs","repos_url":"https://api.github.com/users/MartinNowak/repos","events_url":"https://api.github.com/users/MartinNowak/events{/privacy}","received_events_url":"https://api.github.com/users/MartinNowak/received_events","type":"User","site_admin":false},"body":"Should mention \"for the given dimension\" or so.","created_at":"2015-09-26T01:55:38Z","updated_at":"2015-09-26T01:55:38Z","html_url":"https://github.com/D-Programming-Language/dlang.org/pull/1095#discussion_r40488872","pull_request_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/1095","_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/comments/40488872"},"html":{"href":"https://github.com/D-Programming-Language/dlang.org/pull/1095#discussion_r40488872"},"pull_request":{"href":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/1095"}}},"pull_request":{"url":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/1095","id":44384962,"html_url":"https://github.com/D-Programming-Language/dlang.org/pull/1095","diff_url":"https://github.com/D-Programming-Language/dlang.org/pull/1095.diff","patch_url":"https://github.com/D-Programming-Language/dlang.org/pull/1095.patch","issue_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/issues/1095","number":1095,"state":"open","locked":false,"title":"Full working example of 2D array with operator overloading.","user":{"login":"quickfur","id":405446,"avatar_url":"https://avatars.githubusercontent.com/u/405446?v=3","gravatar_id":"","url":"https://api.github.com/users/quickfur","html_url":"https://github.com/quickfur","followers_url":"https://api.github.com/users/quickfur/followers","following_url":"https://api.github.com/users/quickfur/following{/other_user}","gists_url":"https://api.github.com/users/quickfur/gists{/gist_id}","starred_url":"https://api.github.com/users/quickfur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quickfur/subscriptions","organizations_url":"https://api.github.com/users/quickfur/orgs","repos_url":"https://api.github.com/users/quickfur/repos","events_url":"https://api.github.com/users/quickfur/events{/privacy}","received_events_url":"https://api.github.com/users/quickfur/received_events","type":"User","site_admin":false},"body":"Add fully working code example of a 2D array that overloads the indexing, slicing, and opDollar operators, since it may not be obvious what is the correct way to implement `opSlice` and `opDollar`.","created_at":"2015-09-08T01:00:39Z","updated_at":"2015-09-26T01:55:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"acf6fddf94bc61640763d6219133799a867f7e0a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/1095/commits","review_comments_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/1095/comments","review_comment_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/comments{/number}","comments_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/issues/1095/comments","statuses_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/statuses/4faee59920bc7ec3252495a965191fc20e4c67f8","head":{"label":"quickfur:array2d_example","ref":"array2d_example","sha":"4faee59920bc7ec3252495a965191fc20e4c67f8","user":{"login":"quickfur","id":405446,"avatar_url":"https://avatars.githubusercontent.com/u/405446?v=3","gravatar_id":"","url":"https://api.github.com/users/quickfur","html_url":"https://github.com/quickfur","followers_url":"https://api.github.com/users/quickfur/followers","following_url":"https://api.github.com/users/quickfur/following{/other_user}","gists_url":"https://api.github.com/users/quickfur/gists{/gist_id}","starred_url":"https://api.github.com/users/quickfur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quickfur/subscriptions","organizations_url":"https://api.github.com/users/quickfur/orgs","repos_url":"https://api.github.com/users/quickfur/repos","events_url":"https://api.github.com/users/quickfur/events{/privacy}","received_events_url":"https://api.github.com/users/quickfur/received_events","type":"User","site_admin":false},"repo":{"id":3542444,"name":"dlang.org","full_name":"quickfur/dlang.org","owner":{"login":"quickfur","id":405446,"avatar_url":"https://avatars.githubusercontent.com/u/405446?v=3","gravatar_id":"","url":"https://api.github.com/users/quickfur","html_url":"https://github.com/quickfur","followers_url":"https://api.github.com/users/quickfur/followers","following_url":"https://api.github.com/users/quickfur/following{/other_user}","gists_url":"https://api.github.com/users/quickfur/gists{/gist_id}","starred_url":"https://api.github.com/users/quickfur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quickfur/subscriptions","organizations_url":"https://api.github.com/users/quickfur/orgs","repos_url":"https://api.github.com/users/quickfur/repos","events_url":"https://api.github.com/users/quickfur/events{/privacy}","received_events_url":"https://api.github.com/users/quickfur/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/quickfur/dlang.org","description":"Pages for the d-programming-language.org web site","fork":true,"url":"https://api.github.com/repos/quickfur/dlang.org","forks_url":"https://api.github.com/repos/quickfur/dlang.org/forks","keys_url":"https://api.github.com/repos/quickfur/dlang.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/quickfur/dlang.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/quickfur/dlang.org/teams","hooks_url":"https://api.github.com/repos/quickfur/dlang.org/hooks","issue_events_url":"https://api.github.com/repos/quickfur/dlang.org/issues/events{/number}","events_url":"https://api.github.com/repos/quickfur/dlang.org/events","assignees_url":"https://api.github.com/repos/quickfur/dlang.org/assignees{/user}","branches_url":"https://api.github.com/repos/quickfur/dlang.org/branches{/branch}","tags_url":"https://api.github.com/repos/quickfur/dlang.org/tags","blobs_url":"https://api.github.com/repos/quickfur/dlang.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/quickfur/dlang.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/quickfur/dlang.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/quickfur/dlang.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/quickfur/dlang.org/statuses/{sha}","languages_url":"https://api.github.com/repos/quickfur/dlang.org/languages","stargazers_url":"https://api.github.com/repos/quickfur/dlang.org/stargazers","contributors_url":"https://api.github.com/repos/quickfur/dlang.org/contributors","subscribers_url":"https://api.github.com/repos/quickfur/dlang.org/subscribers","subscription_url":"https://api.github.com/repos/quickfur/dlang.org/subscription","commits_url":"https://api.github.com/repos/quickfur/dlang.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/quickfur/dlang.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/quickfur/dlang.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/quickfur/dlang.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/quickfur/dlang.org/contents/{+path}","compare_url":"https://api.github.com/repos/quickfur/dlang.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/quickfur/dlang.org/merges","archive_url":"https://api.github.com/repos/quickfur/dlang.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/quickfur/dlang.org/downloads","issues_url":"https://api.github.com/repos/quickfur/dlang.org/issues{/number}","pulls_url":"https://api.github.com/repos/quickfur/dlang.org/pulls{/number}","milestones_url":"https://api.github.com/repos/quickfur/dlang.org/milestones{/number}","notifications_url":"https://api.github.com/repos/quickfur/dlang.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/quickfur/dlang.org/labels{/name}","releases_url":"https://api.github.com/repos/quickfur/dlang.org/releases{/id}","created_at":"2012-02-25T04:35:33Z","updated_at":"2015-03-24T00:31:32Z","pushed_at":"2015-09-11T15:02:32Z","git_url":"git://github.com/quickfur/dlang.org.git","ssh_url":"git@github.com:quickfur/dlang.org.git","clone_url":"https://github.com/quickfur/dlang.org.git","svn_url":"https://github.com/quickfur/dlang.org","homepage":"d-programming-language.org","size":11125,"stargazers_count":1,"watchers_count":1,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"D-Programming-Language:master","ref":"master","sha":"634643d3cca8cafb42023d63b25382a5c2300716","user":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"repo":{"id":1257080,"name":"dlang.org","full_name":"D-Programming-Language/dlang.org","owner":{"login":"D-Programming-Language","id":565913,"avatar_url":"https://avatars.githubusercontent.com/u/565913?v=3","gravatar_id":"","url":"https://api.github.com/users/D-Programming-Language","html_url":"https://github.com/D-Programming-Language","followers_url":"https://api.github.com/users/D-Programming-Language/followers","following_url":"https://api.github.com/users/D-Programming-Language/following{/other_user}","gists_url":"https://api.github.com/users/D-Programming-Language/gists{/gist_id}","starred_url":"https://api.github.com/users/D-Programming-Language/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/D-Programming-Language/subscriptions","organizations_url":"https://api.github.com/users/D-Programming-Language/orgs","repos_url":"https://api.github.com/users/D-Programming-Language/repos","events_url":"https://api.github.com/users/D-Programming-Language/events{/privacy}","received_events_url":"https://api.github.com/users/D-Programming-Language/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/D-Programming-Language/dlang.org","description":"Pages for the dlang.org website, home of the D Programming Language","fork":false,"url":"https://api.github.com/repos/D-Programming-Language/dlang.org","forks_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/forks","keys_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/teams","hooks_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/hooks","issue_events_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/issues/events{/number}","events_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/events","assignees_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/assignees{/user}","branches_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/branches{/branch}","tags_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/tags","blobs_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/statuses/{sha}","languages_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/languages","stargazers_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/stargazers","contributors_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/contributors","subscribers_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/subscribers","subscription_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/subscription","commits_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/contents/{+path}","compare_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/merges","archive_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/downloads","issues_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/issues{/number}","pulls_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls{/number}","milestones_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/milestones{/number}","notifications_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/labels{/name}","releases_url":"https://api.github.com/repos/D-Programming-Language/dlang.org/releases{/id}","created_at":"2011-01-15T06:58:12Z","updated_at":"2015-09-24T06:08:11Z","pushed_at":"2015-09-25T20:58:57Z","git_url":"git://github.com/D-Programming-Language/dlang.org.git","ssh_url":"git@github.com:D-Programming-Language/dlang.org.git","clone_url":"https://github.com/D-Programming-Language/dlang.org.git","svn_url":"https://github.com/D-Programming-Language/dlang.org","homepage":"dlang.org","size":20364,"stargazers_count":167,"watchers_count":167,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":218,"mirror_url":null,"open_issues_count":27,"forks":218,"open_issues":27,"watchers":167,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/1095"},"html":{"href":"https://github.com/D-Programming-Language/dlang.org/pull/1095"},"issue":{"href":"https://api.github.com/repos/D-Programming-Language/dlang.org/issues/1095"},"comments":{"href":"https://api.github.com/repos/D-Programming-Language/dlang.org/issues/1095/comments"},"review_comments":{"href":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/1095/comments"},"review_comment":{"href":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/D-Programming-Language/dlang.org/pulls/1095/commits"},"statuses":{"href":"https://api.github.com/repos/D-Programming-Language/dlang.org/statuses/4faee59920bc7ec3252495a965191fc20e4c67f8"}}}}