{"action":"created","comment":{"url":"https://api.github.com/repos/Tarasow/lab4/pulls/comments/61998479","id":61998479,"diff_hunk":"@@ -58,53 +59,77 @@ istream& operator>> (istream& is, elem& e) {\n \n class matr {\n public:\n-\telem **e;\n-\tint n, m;\n-\tmatr(int a, int b, const elem* o, int so) {\n+\telem **e; // public?\n+\tint n, m; // public? unsigned!\n+\tmatr(int a, int b, const elem* o, int so) { // предлагаю сократить до двух параметров\n \t\tn = a;\n \t\tm = b;\n \t\tint k = 0;\n-\t\te = static_cast<elem**>(operator new[](n * sizeof(elem**)));\n+\t\t// здесь необоснованно и неправильно (см. деструктор) используется placement new\n+\t\te = new elem*[n];\n \t\tfor (int i = 0; i < n; i++)\n-\t\t\te[i] = static_cast<elem*>(operator new[](m * sizeof(elem*)));\n+\t\t\te[i] = static_cast<elem*>(operator new[](m * sizeof(elem)));\n \t\tfor (int i = 0; i < n; i++) {\n \t\t\tfor (int j = 0; j < m; j++) {\n \t\t\t\tif (k != so) {\n-\t\t\t\t\tnew(&e[i][j]) elem(o[k]);\n+\t\t\t\t\tnew(&(e[i][j])) elem(o[k]);\n \t\t\t\t\tk++;\n \t\t\t\t}\n-\t\t\t\telse new(&e[i][j]) elem();\n+\t\t\t\telse new(&(e[i][j])) elem(); // зачем placement new, если у объекта есть конструктор по умолчанию?\n \t\t\t}\n \t\t}\n \t}\n \n+\tmatr(matr&& mat) {\n+\t\te = mat.e;\n+\t\tm = mat.m;\n+\t\tn = mat.n;\n+\t\tmat.e = nullptr;\n+\t}\n+\n+\tmatr& operator=(matr&& mat) {\n+\t\te = mat.e;\n+\t\tm = mat.m;\n+\t\tn = mat.n;\n+\t\tmat.e = nullptr;\n+\t\treturn *this;\n+\t}\n \t\n \t~matr() {\n-\t\tif (e != nullptr)\n-\t\t\tfor (int i = 0; i < n; i++)\n-\t\t\t\tfor (int j = 0; j < m; j++) e[i][j].~elem();\n+\t\tif (e != nullptr) { // теперь деструктор работает правильно, но это не значит, что placement new был использован обоснованно\n+\t\t\tfor (int i = 0; i < n; i++) {\n+\t\t\t\tfor (int j = 0; j < m; j++) {\n+\t\t\t\t\te[i][j].~elem();\n+\t\t\t\t}\n+\t\t\t\toperator delete[](static_cast<void*>(e[i]));\n+\t\t\t}\n+\t\t\tdelete [] e;\t\t\t\n+\t\t}\n+\n \t}\n \t\n \n-\tconst elem& operator() (int a, int b) {\n+\tconst elem& operator() (int a, int b) { // uint?\n \t\tif (a < 0 || b < 0 || a >= n || b >= m) throw \"Error! Can't get element by index\";\n \t\treturn e[a][b];\n \t}\n \n \tmatr& operator~ () {\n-\t\telem *a = new elem[n*m];\n-\t\tmatr f(m, n, a, m*n);\n+\t\telem *a = new elem[n*m]; // страдаете от лишних параметров конструктора\n+\t\tmatr f(m, n, a, m*n); // что, если бросит исключение?\n \t\tdelete[] a;\n \t\tfor (int i = 0; i < m; i++) {\n \t\t\tfor (int j = 0; j < n; j++) f.e[i][j] = e[j][m - i - 1]; //= e[n - j - 1][i] - another turn\n \t\t}\n-\t\tswap(f, *this);\n+\t\tswap(f, *this); // move-constructible & move-assignable!\n+\t\t// http://www.cplusplus.com/reference/algorithm/swap/\n+\t\t// иначе нужен конструктор копирования","path":"2lab4.cpp","position":137,"original_position":137,"commit_id":"f5c3b5ee5122084c2d13e43bbbdbe0f8101ca027","original_commit_id":"f5c3b5ee5122084c2d13e43bbbdbe0f8101ca027","user":{"login":"Mironenko","id":2317146,"avatar_url":"https://avatars.githubusercontent.com/u/2317146?v=3","gravatar_id":"","url":"https://api.github.com/users/Mironenko","html_url":"https://github.com/Mironenko","followers_url":"https://api.github.com/users/Mironenko/followers","following_url":"https://api.github.com/users/Mironenko/following{/other_user}","gists_url":"https://api.github.com/users/Mironenko/gists{/gist_id}","starred_url":"https://api.github.com/users/Mironenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mironenko/subscriptions","organizations_url":"https://api.github.com/users/Mironenko/orgs","repos_url":"https://api.github.com/users/Mironenko/repos","events_url":"https://api.github.com/users/Mironenko/events{/privacy}","received_events_url":"https://api.github.com/users/Mironenko/received_events","type":"User","site_admin":false},"body":"Да. Либо используется swap, задействующий конструктор копирования (в вашем случае двойное удаление), либо, если есть move-ctor & move-assign, то swap, использующий их.","created_at":"2016-05-04T07:30:29Z","updated_at":"2016-05-04T07:30:29Z","html_url":"https://github.com/Tarasow/lab4/pull/1#discussion_r61998479","pull_request_url":"https://api.github.com/repos/Tarasow/lab4/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/Tarasow/lab4/pulls/comments/61998479"},"html":{"href":"https://github.com/Tarasow/lab4/pull/1#discussion_r61998479"},"pull_request":{"href":"https://api.github.com/repos/Tarasow/lab4/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/Tarasow/lab4/pulls/1","id":68712764,"html_url":"https://github.com/Tarasow/lab4/pull/1","diff_url":"https://github.com/Tarasow/lab4/pull/1.diff","patch_url":"https://github.com/Tarasow/lab4/pull/1.patch","issue_url":"https://api.github.com/repos/Tarasow/lab4/issues/1","number":1,"state":"open","locked":false,"title":"Review","user":{"login":"Mironenko","id":2317146,"avatar_url":"https://avatars.githubusercontent.com/u/2317146?v=3","gravatar_id":"","url":"https://api.github.com/users/Mironenko","html_url":"https://github.com/Mironenko","followers_url":"https://api.github.com/users/Mironenko/followers","following_url":"https://api.github.com/users/Mironenko/following{/other_user}","gists_url":"https://api.github.com/users/Mironenko/gists{/gist_id}","starred_url":"https://api.github.com/users/Mironenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mironenko/subscriptions","organizations_url":"https://api.github.com/users/Mironenko/orgs","repos_url":"https://api.github.com/users/Mironenko/repos","events_url":"https://api.github.com/users/Mironenko/events{/privacy}","received_events_url":"https://api.github.com/users/Mironenko/received_events","type":"User","site_admin":false},"body":"3.3","created_at":"2016-05-03T14:17:34Z","updated_at":"2016-05-04T07:30:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"90add91e17c5d0a30d39af78b3297ef22fc019be","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Tarasow/lab4/pulls/1/commits","review_comments_url":"https://api.github.com/repos/Tarasow/lab4/pulls/1/comments","review_comment_url":"https://api.github.com/repos/Tarasow/lab4/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Tarasow/lab4/issues/1/comments","statuses_url":"https://api.github.com/repos/Tarasow/lab4/statuses/f5c3b5ee5122084c2d13e43bbbdbe0f8101ca027","head":{"label":"Mironenko:review","ref":"review","sha":"f5c3b5ee5122084c2d13e43bbbdbe0f8101ca027","user":{"login":"Mironenko","id":2317146,"avatar_url":"https://avatars.githubusercontent.com/u/2317146?v=3","gravatar_id":"","url":"https://api.github.com/users/Mironenko","html_url":"https://github.com/Mironenko","followers_url":"https://api.github.com/users/Mironenko/followers","following_url":"https://api.github.com/users/Mironenko/following{/other_user}","gists_url":"https://api.github.com/users/Mironenko/gists{/gist_id}","starred_url":"https://api.github.com/users/Mironenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mironenko/subscriptions","organizations_url":"https://api.github.com/users/Mironenko/orgs","repos_url":"https://api.github.com/users/Mironenko/repos","events_url":"https://api.github.com/users/Mironenko/events{/privacy}","received_events_url":"https://api.github.com/users/Mironenko/received_events","type":"User","site_admin":false},"repo":{"id":57974715,"name":"lab4-2","full_name":"Mironenko/lab4-2","owner":{"login":"Mironenko","id":2317146,"avatar_url":"https://avatars.githubusercontent.com/u/2317146?v=3","gravatar_id":"","url":"https://api.github.com/users/Mironenko","html_url":"https://github.com/Mironenko","followers_url":"https://api.github.com/users/Mironenko/followers","following_url":"https://api.github.com/users/Mironenko/following{/other_user}","gists_url":"https://api.github.com/users/Mironenko/gists{/gist_id}","starred_url":"https://api.github.com/users/Mironenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mironenko/subscriptions","organizations_url":"https://api.github.com/users/Mironenko/orgs","repos_url":"https://api.github.com/users/Mironenko/repos","events_url":"https://api.github.com/users/Mironenko/events{/privacy}","received_events_url":"https://api.github.com/users/Mironenko/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Mironenko/lab4-2","description":"","fork":true,"url":"https://api.github.com/repos/Mironenko/lab4-2","forks_url":"https://api.github.com/repos/Mironenko/lab4-2/forks","keys_url":"https://api.github.com/repos/Mironenko/lab4-2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Mironenko/lab4-2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Mironenko/lab4-2/teams","hooks_url":"https://api.github.com/repos/Mironenko/lab4-2/hooks","issue_events_url":"https://api.github.com/repos/Mironenko/lab4-2/issues/events{/number}","events_url":"https://api.github.com/repos/Mironenko/lab4-2/events","assignees_url":"https://api.github.com/repos/Mironenko/lab4-2/assignees{/user}","branches_url":"https://api.github.com/repos/Mironenko/lab4-2/branches{/branch}","tags_url":"https://api.github.com/repos/Mironenko/lab4-2/tags","blobs_url":"https://api.github.com/repos/Mironenko/lab4-2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Mironenko/lab4-2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Mironenko/lab4-2/git/refs{/sha}","trees_url":"https://api.github.com/repos/Mironenko/lab4-2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Mironenko/lab4-2/statuses/{sha}","languages_url":"https://api.github.com/repos/Mironenko/lab4-2/languages","stargazers_url":"https://api.github.com/repos/Mironenko/lab4-2/stargazers","contributors_url":"https://api.github.com/repos/Mironenko/lab4-2/contributors","subscribers_url":"https://api.github.com/repos/Mironenko/lab4-2/subscribers","subscription_url":"https://api.github.com/repos/Mironenko/lab4-2/subscription","commits_url":"https://api.github.com/repos/Mironenko/lab4-2/commits{/sha}","git_commits_url":"https://api.github.com/repos/Mironenko/lab4-2/git/commits{/sha}","comments_url":"https://api.github.com/repos/Mironenko/lab4-2/comments{/number}","issue_comment_url":"https://api.github.com/repos/Mironenko/lab4-2/issues/comments{/number}","contents_url":"https://api.github.com/repos/Mironenko/lab4-2/contents/{+path}","compare_url":"https://api.github.com/repos/Mironenko/lab4-2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Mironenko/lab4-2/merges","archive_url":"https://api.github.com/repos/Mironenko/lab4-2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Mironenko/lab4-2/downloads","issues_url":"https://api.github.com/repos/Mironenko/lab4-2/issues{/number}","pulls_url":"https://api.github.com/repos/Mironenko/lab4-2/pulls{/number}","milestones_url":"https://api.github.com/repos/Mironenko/lab4-2/milestones{/number}","notifications_url":"https://api.github.com/repos/Mironenko/lab4-2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Mironenko/lab4-2/labels{/name}","releases_url":"https://api.github.com/repos/Mironenko/lab4-2/releases{/id}","deployments_url":"https://api.github.com/repos/Mironenko/lab4-2/deployments","created_at":"2016-05-03T14:16:41Z","updated_at":"2016-05-03T14:16:42Z","pushed_at":"2016-05-03T14:17:06Z","git_url":"git://github.com/Mironenko/lab4-2.git","ssh_url":"git@github.com:Mironenko/lab4-2.git","clone_url":"https://github.com/Mironenko/lab4-2.git","svn_url":"https://github.com/Mironenko/lab4-2","homepage":null,"size":6,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Tarasow:master","ref":"master","sha":"3d84dd678448fc110ff9c63a3329f31b4ec7380e","user":{"login":"Tarasow","id":17967964,"avatar_url":"https://avatars.githubusercontent.com/u/17967964?v=3","gravatar_id":"","url":"https://api.github.com/users/Tarasow","html_url":"https://github.com/Tarasow","followers_url":"https://api.github.com/users/Tarasow/followers","following_url":"https://api.github.com/users/Tarasow/following{/other_user}","gists_url":"https://api.github.com/users/Tarasow/gists{/gist_id}","starred_url":"https://api.github.com/users/Tarasow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tarasow/subscriptions","organizations_url":"https://api.github.com/users/Tarasow/orgs","repos_url":"https://api.github.com/users/Tarasow/repos","events_url":"https://api.github.com/users/Tarasow/events{/privacy}","received_events_url":"https://api.github.com/users/Tarasow/received_events","type":"User","site_admin":false},"repo":{"id":55292383,"name":"lab4","full_name":"Tarasow/lab4","owner":{"login":"Tarasow","id":17967964,"avatar_url":"https://avatars.githubusercontent.com/u/17967964?v=3","gravatar_id":"","url":"https://api.github.com/users/Tarasow","html_url":"https://github.com/Tarasow","followers_url":"https://api.github.com/users/Tarasow/followers","following_url":"https://api.github.com/users/Tarasow/following{/other_user}","gists_url":"https://api.github.com/users/Tarasow/gists{/gist_id}","starred_url":"https://api.github.com/users/Tarasow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tarasow/subscriptions","organizations_url":"https://api.github.com/users/Tarasow/orgs","repos_url":"https://api.github.com/users/Tarasow/repos","events_url":"https://api.github.com/users/Tarasow/events{/privacy}","received_events_url":"https://api.github.com/users/Tarasow/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Tarasow/lab4","description":"","fork":false,"url":"https://api.github.com/repos/Tarasow/lab4","forks_url":"https://api.github.com/repos/Tarasow/lab4/forks","keys_url":"https://api.github.com/repos/Tarasow/lab4/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Tarasow/lab4/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Tarasow/lab4/teams","hooks_url":"https://api.github.com/repos/Tarasow/lab4/hooks","issue_events_url":"https://api.github.com/repos/Tarasow/lab4/issues/events{/number}","events_url":"https://api.github.com/repos/Tarasow/lab4/events","assignees_url":"https://api.github.com/repos/Tarasow/lab4/assignees{/user}","branches_url":"https://api.github.com/repos/Tarasow/lab4/branches{/branch}","tags_url":"https://api.github.com/repos/Tarasow/lab4/tags","blobs_url":"https://api.github.com/repos/Tarasow/lab4/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Tarasow/lab4/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Tarasow/lab4/git/refs{/sha}","trees_url":"https://api.github.com/repos/Tarasow/lab4/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Tarasow/lab4/statuses/{sha}","languages_url":"https://api.github.com/repos/Tarasow/lab4/languages","stargazers_url":"https://api.github.com/repos/Tarasow/lab4/stargazers","contributors_url":"https://api.github.com/repos/Tarasow/lab4/contributors","subscribers_url":"https://api.github.com/repos/Tarasow/lab4/subscribers","subscription_url":"https://api.github.com/repos/Tarasow/lab4/subscription","commits_url":"https://api.github.com/repos/Tarasow/lab4/commits{/sha}","git_commits_url":"https://api.github.com/repos/Tarasow/lab4/git/commits{/sha}","comments_url":"https://api.github.com/repos/Tarasow/lab4/comments{/number}","issue_comment_url":"https://api.github.com/repos/Tarasow/lab4/issues/comments{/number}","contents_url":"https://api.github.com/repos/Tarasow/lab4/contents/{+path}","compare_url":"https://api.github.com/repos/Tarasow/lab4/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Tarasow/lab4/merges","archive_url":"https://api.github.com/repos/Tarasow/lab4/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Tarasow/lab4/downloads","issues_url":"https://api.github.com/repos/Tarasow/lab4/issues{/number}","pulls_url":"https://api.github.com/repos/Tarasow/lab4/pulls{/number}","milestones_url":"https://api.github.com/repos/Tarasow/lab4/milestones{/number}","notifications_url":"https://api.github.com/repos/Tarasow/lab4/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Tarasow/lab4/labels{/name}","releases_url":"https://api.github.com/repos/Tarasow/lab4/releases{/id}","deployments_url":"https://api.github.com/repos/Tarasow/lab4/deployments","created_at":"2016-04-02T12:02:46Z","updated_at":"2016-04-02T12:03:43Z","pushed_at":"2016-05-03T14:17:35Z","git_url":"git://github.com/Tarasow/lab4.git","ssh_url":"git@github.com:Tarasow/lab4.git","clone_url":"https://github.com/Tarasow/lab4.git","svn_url":"https://github.com/Tarasow/lab4","homepage":null,"size":4,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Tarasow/lab4/pulls/1"},"html":{"href":"https://github.com/Tarasow/lab4/pull/1"},"issue":{"href":"https://api.github.com/repos/Tarasow/lab4/issues/1"},"comments":{"href":"https://api.github.com/repos/Tarasow/lab4/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/Tarasow/lab4/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/Tarasow/lab4/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Tarasow/lab4/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/Tarasow/lab4/statuses/f5c3b5ee5122084c2d13e43bbbdbe0f8101ca027"}}}}