GitHub PullRequestReviewCommentEvent at 2014-06-20 18:32:11
Repository: orly
Actor: cmaloney
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/orlyatomics/orly/pulls/comments/14034411","id":14034411,"diff_hunk":"@@ -23,72 +23,107 @@\n #include <string>\n #include <vector>\n \n+#include <util/tuple.h>\n+\n namespace Base {\n \n-  // TODO: Add a variant of the stream insertion that allows passing an element callback.\n-  template <typename TSepType, typename TContainer>\n-  class TJoin {\n-    public:\n-    TJoin(const TSepType &sep, const TContainer &container) : Sep(sep), Container(container) {}\n+  template <typename TContainer, typename TDelimiter, typename TFormat>\n+  struct TJoin {\n+\n+    TJoin(const TContainer &container,\n+          const TDelimiter &delimiter,\n+          const TFormat &format)\n+        : Container(container),\n+          Delimiter(delimiter),\n+          Format(format) {}\n \n-    const TSepType &Sep;\n     const TContainer &Container;\n-  };\n-\n-  template <typename TSepType, typename TContainer>\n-  std::ostream &operator<<(std::ostream &out, const TJoin<TSepType, TContainer> &join) {\n-    bool first = true;\n-    for(const auto &elem: join.Container) {\n-      if (first) {\n-        first = false;\n-      } else {\n-        out << join.Sep;\n-      }\n-\n-      out << elem;\n-    }\n \n-    return out;\n-  }\n+    const TDelimiter &Delimiter;\n \n-  // TODO: Migrate other uses of Join to this one which is more fluid to use in stream insertions.\n-  template <typename TSepType, typename TContainer>\n-  auto Join(const TSepType &sep, const TContainer &container) {\n-    return TJoin<TSepType, TContainer>(sep, container);\n+    const TFormat &Format;\n+\n+  };  // TJoin\n+\n+  template <typename TContainer, typename TDelimiter, typename TFormat>\n+  auto Join(const TContainer &container,\n+            const TDelimiter &delimiter,\n+            const TFormat &format) {\n+    return TJoin<TContainer, TDelimiter, TFormat>(container, delimiter, format);\n   }\n \n-  //NOTE: pieces_container must be able to have foreach run over it, and what it contains must\n-  template<typename TSepType, typename TVal, typename TStrm>\n-  TStrm &Join(const TSepType &sep, const TVal &pieces_container, TStrm &out) {\n-    bool first = true;\n-    for (auto it: pieces_container) {\n-      if (first) {\n-        first = false;\n-      } else {\n-        out << sep;\n-      }\n-      out << it;\n-    }\n+  template <typename TContainer, typename TDelimiter>\n+  auto Join(const TContainer &container, const TDelimiter &delimiter) {\n+    return Join(container,\n+                delimiter,\n+                [](auto &strm, const auto &elem) {\n+                  strm << elem;\n+                });\n+  }\n \n-    return out;\n+  /* A generic function to stream out TJoin<> to some streamer.\n+     The streamer type is templated to handle other streamers such as TCppPrinter. */\n+  template <typename TStrm,\n+            typename TContainer,\n+            typename TDelimiter,\n+            typename TFormat>\n+  TStrm &WriteJoin(TStrm &strm,\n+                   const TJoin<TContainer, TDelimiter, TFormat> &that) {\n+    for (const auto &elem : that.Container) {\n+      if (&elem != &*std::begin(that.Container)) {\n+        strm << that.Delimiter;\n+      }  // if\n+      that.Format(strm, elem);\n+    }  // for\n+    return strm;\n   }\n \n-  //TODO: Tighter specification of TCb\n-  template<typename TSepType, typename TVal, typename TCb, typename TStrm>\n-  TStrm &Join(const TSepType &sep, const TVal &pieces_container, const TCb &cb,  TStrm &out) {\n-    bool first = true;\n-    for (const auto &it: pieces_container) {\n-      if (first) {\n-        first = false;\n-      } else {\n-        out << sep;\n-      }\n-      cb(it, out);\n+  template <typename TStrm, typename TDelimiter, typename TFormat>\n+  struct TWriteTuple {","path":"base/split.h","position":110,"original_position":110,"commit_id":"badaacbdf44596a00349bd1ca4b0e142f8685ae2","original_commit_id":"badaacbdf44596a00349bd1ca4b0e142f8685ae2","user":{"login":"cmaloney","id":751088,"avatar_url":"https://avatars.githubusercontent.com/u/751088?","gravatar_id":"82b310bf4c734ef6143e860b896c89bf","url":"https://api.github.com/users/cmaloney","html_url":"https://github.com/cmaloney","followers_url":"https://api.github.com/users/cmaloney/followers","following_url":"https://api.github.com/users/cmaloney/following{/other_user}","gists_url":"https://api.github.com/users/cmaloney/gists{/gist_id}","starred_url":"https://api.github.com/users/cmaloney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmaloney/subscriptions","organizations_url":"https://api.github.com/users/cmaloney/orgs","repos_url":"https://api.github.com/users/cmaloney/repos","events_url":"https://api.github.com/users/cmaloney/events{/privacy}","received_events_url":"https://api.github.com/users/cmaloney/received_events","type":"User","site_admin":false},"body":"Thoughts on changing <strm/bin/out.h> to use this for it's WriteTuple?","created_at":"2014-06-20T18:32:11Z","updated_at":"2014-06-20T18:32:11Z","html_url":"https://github.com/orlyatomics/orly/pull/129#discussion_r14034411","pull_request_url":"https://api.github.com/repos/orlyatomics/orly/pulls/129","_links":{"self":{"href":"https://api.github.com/repos/orlyatomics/orly/pulls/comments/14034411"},"html":{"href":"https://github.com/orlyatomics/orly/pull/129#discussion_r14034411"},"pull_request":{"href":"https://api.github.com/repos/orlyatomics/orly/pulls/129"}}},"pull_request":{"url":"https://api.github.com/repos/orlyatomics/orly/pulls/129","id":17398448,"html_url":"https://github.com/orlyatomics/orly/pull/129","diff_url":"https://github.com/orlyatomics/orly/pull/129.diff","patch_url":"https://github.com/orlyatomics/orly/pull/129.patch","issue_url":"https://api.github.com/repos/orlyatomics/orly/issues/129","number":129,"state":"open","title":"Removed uses of gcc internal, std::_Tuple_impl and updated Base::Join.","user":{"login":"mpark","id":2275240,"avatar_url":"https://avatars.githubusercontent.com/u/2275240?","gravatar_id":null,"url":"https://api.github.com/users/mpark","html_url":"https://github.com/mpark","followers_url":"https://api.github.com/users/mpark/followers","following_url":"https://api.github.com/users/mpark/following{/other_user}","gists_url":"https://api.github.com/users/mpark/gists{/gist_id}","starred_url":"https://api.github.com/users/mpark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpark/subscriptions","organizations_url":"https://api.github.com/users/mpark/orgs","repos_url":"https://api.github.com/users/mpark/repos","events_url":"https://api.github.com/users/mpark/events{/privacy}","received_events_url":"https://api.github.com/users/mpark/received_events","type":"User","site_admin":false},"body":"Lots of clean-up.\r\n\r\n#### Util::ForEach(Tuple, UnaryFn)\r\n__Don't need index, pass a lambda.__\r\n```\r\nstd::tuple<int, std::string> tuple(0, \"begin\");\r\nstd::istringstream strm(\"1 end\");\r\nForEach(tuple, [](const auto &elem) { std::cout << elem << std::endl; });\r\nForEach(tuple, [&strm](auto &elem) { strm >> elem; });\r\nForEach(tuple, [](const auto &elem) { std::cout << elem << std::endl; });\r\n```\r\nPrints:\r\n```\r\n0\r\nbegin\r\n1\r\nend\r\n```\r\n__Need the index, pass a functor.__\r\n```\r\nstruct TPrint {\r\n  \r\n  explicit TPrint(std::ostream &strm) : Strm(strm) {}\r\n\r\n  template <std::size_t I, typename TElem>\r\n  void operator()(const TElem &elem) const {\r\n    (I ? Strm << \", \" : Strm) << elem;\r\n  }\r\n\r\n  private:\r\n\r\n  std::ostream &Strm;\r\n\r\n};  // TPrint\r\n\r\nForEach(tuple, TPrint(std::cout));\r\n```\r\nPrints: `1, end`\r\n\r\n#### Base::Join(Container, Delimiter, Format?)\r\n```\r\nauto tuple = std::make_tuple(42, 1.1, \"hello\");\r\nstd::cout << Base::Join(tuple,\r\n                        \", \",\r\n                        [](std::ostream &strm, const auto &elem) {\r\n                          strm << '(' << elem << ')';\r\n                        }) << std::endl;\r\n```\r\nPrints: `(42), (1.1), (hello)`\r\n\r\nIf `Format` function is not provided, it defaults to: `[](auto &strm, const auto &elem) { strm << elem; }`\r\n\r\n#### Base::AsStr(Arg)\r\nBack to being a one argument function. If you're looking for the variadic version, use the `std::tuple` specialization for `Join`.\r\n\r\nExample:\r\n```\r\nstd::string text = AsStr(Join(std::forward_as_tuple(42, 1.1, \"hello\"),\r\n                              ' ',\r\n                              [](std::ostream &strm, const auto &elem) {\r\n                                strm << '[' << elem << ']';\r\n                              });\r\nstd::cout << text << std::endl;\r\n```\r\nPrints: `[42] [1.1] [hello]`","created_at":"2014-06-20T10:23:55Z","updated_at":"2014-06-20T18:32:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c2999489c279dedf4738f03ab0bd2718b517d79c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/orlyatomics/orly/pulls/129/commits","review_comments_url":"https://api.github.com/repos/orlyatomics/orly/pulls/129/comments","review_comment_url":"https://api.github.com/repos/orlyatomics/orly/pulls/comments/{number}","comments_url":"https://api.github.com/repos/orlyatomics/orly/issues/129/comments","statuses_url":"https://api.github.com/repos/orlyatomics/orly/statuses/badaacbdf44596a00349bd1ca4b0e142f8685ae2","head":{"label":"mpark:tuple","ref":"tuple","sha":"badaacbdf44596a00349bd1ca4b0e142f8685ae2","user":{"login":"mpark","id":2275240,"avatar_url":"https://avatars.githubusercontent.com/u/2275240?","gravatar_id":null,"url":"https://api.github.com/users/mpark","html_url":"https://github.com/mpark","followers_url":"https://api.github.com/users/mpark/followers","following_url":"https://api.github.com/users/mpark/following{/other_user}","gists_url":"https://api.github.com/users/mpark/gists{/gist_id}","starred_url":"https://api.github.com/users/mpark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpark/subscriptions","organizations_url":"https://api.github.com/users/mpark/orgs","repos_url":"https://api.github.com/users/mpark/repos","events_url":"https://api.github.com/users/mpark/events{/privacy}","received_events_url":"https://api.github.com/users/mpark/received_events","type":"User","site_admin":false},"repo":{"id":19601785,"name":"orly","full_name":"mpark/orly","owner":{"login":"mpark","id":2275240,"avatar_url":"https://avatars.githubusercontent.com/u/2275240?","gravatar_id":null,"url":"https://api.github.com/users/mpark","html_url":"https://github.com/mpark","followers_url":"https://api.github.com/users/mpark/followers","following_url":"https://api.github.com/users/mpark/following{/other_user}","gists_url":"https://api.github.com/users/mpark/gists{/gist_id}","starred_url":"https://api.github.com/users/mpark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpark/subscriptions","organizations_url":"https://api.github.com/users/mpark/orgs","repos_url":"https://api.github.com/users/mpark/repos","events_url":"https://api.github.com/users/mpark/events{/privacy}","received_events_url":"https://api.github.com/users/mpark/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mpark/orly","description":"Orly™ Graph Database","fork":true,"url":"https://api.github.com/repos/mpark/orly","forks_url":"https://api.github.com/repos/mpark/orly/forks","keys_url":"https://api.github.com/repos/mpark/orly/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mpark/orly/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mpark/orly/teams","hooks_url":"https://api.github.com/repos/mpark/orly/hooks","issue_events_url":"https://api.github.com/repos/mpark/orly/issues/events{/number}","events_url":"https://api.github.com/repos/mpark/orly/events","assignees_url":"https://api.github.com/repos/mpark/orly/assignees{/user}","branches_url":"https://api.github.com/repos/mpark/orly/branches{/branch}","tags_url":"https://api.github.com/repos/mpark/orly/tags","blobs_url":"https://api.github.com/repos/mpark/orly/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mpark/orly/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mpark/orly/git/refs{/sha}","trees_url":"https://api.github.com/repos/mpark/orly/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mpark/orly/statuses/{sha}","languages_url":"https://api.github.com/repos/mpark/orly/languages","stargazers_url":"https://api.github.com/repos/mpark/orly/stargazers","contributors_url":"https://api.github.com/repos/mpark/orly/contributors","subscribers_url":"https://api.github.com/repos/mpark/orly/subscribers","subscription_url":"https://api.github.com/repos/mpark/orly/subscription","commits_url":"https://api.github.com/repos/mpark/orly/commits{/sha}","git_commits_url":"https://api.github.com/repos/mpark/orly/git/commits{/sha}","comments_url":"https://api.github.com/repos/mpark/orly/comments{/number}","issue_comment_url":"https://api.github.com/repos/mpark/orly/issues/comments/{number}","contents_url":"https://api.github.com/repos/mpark/orly/contents/{+path}","compare_url":"https://api.github.com/repos/mpark/orly/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mpark/orly/merges","archive_url":"https://api.github.com/repos/mpark/orly/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mpark/orly/downloads","issues_url":"https://api.github.com/repos/mpark/orly/issues{/number}","pulls_url":"https://api.github.com/repos/mpark/orly/pulls{/number}","milestones_url":"https://api.github.com/repos/mpark/orly/milestones{/number}","notifications_url":"https://api.github.com/repos/mpark/orly/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mpark/orly/labels{/name}","releases_url":"https://api.github.com/repos/mpark/orly/releases{/id}","created_at":"2014-05-09T06:41:54Z","updated_at":"2014-06-20T10:59:50Z","pushed_at":"2014-06-20T10:59:50Z","git_url":"git://github.com/mpark/orly.git","ssh_url":"git@github.com:mpark/orly.git","clone_url":"https://github.com/mpark/orly.git","svn_url":"https://github.com/mpark/orly","homepage":"http://orlyatomics.com/","size":5249,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"orlyatomics:master","ref":"master","sha":"632a6074fd06d337cfb1952ebe29fe40f3bc4efe","user":{"login":"orlyatomics","id":6895367,"avatar_url":"https://avatars.githubusercontent.com/u/6895367?","gravatar_id":"29199d0778ebc85cb93ed4410f071517","url":"https://api.github.com/users/orlyatomics","html_url":"https://github.com/orlyatomics","followers_url":"https://api.github.com/users/orlyatomics/followers","following_url":"https://api.github.com/users/orlyatomics/following{/other_user}","gists_url":"https://api.github.com/users/orlyatomics/gists{/gist_id}","starred_url":"https://api.github.com/users/orlyatomics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orlyatomics/subscriptions","organizations_url":"https://api.github.com/users/orlyatomics/orgs","repos_url":"https://api.github.com/users/orlyatomics/repos","events_url":"https://api.github.com/users/orlyatomics/events{/privacy}","received_events_url":"https://api.github.com/users/orlyatomics/received_events","type":"Organization","site_admin":false},"repo":{"id":18684028,"name":"orly","full_name":"orlyatomics/orly","owner":{"login":"orlyatomics","id":6895367,"avatar_url":"https://avatars.githubusercontent.com/u/6895367?","gravatar_id":"29199d0778ebc85cb93ed4410f071517","url":"https://api.github.com/users/orlyatomics","html_url":"https://github.com/orlyatomics","followers_url":"https://api.github.com/users/orlyatomics/followers","following_url":"https://api.github.com/users/orlyatomics/following{/other_user}","gists_url":"https://api.github.com/users/orlyatomics/gists{/gist_id}","starred_url":"https://api.github.com/users/orlyatomics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orlyatomics/subscriptions","organizations_url":"https://api.github.com/users/orlyatomics/orgs","repos_url":"https://api.github.com/users/orlyatomics/repos","events_url":"https://api.github.com/users/orlyatomics/events{/privacy}","received_events_url":"https://api.github.com/users/orlyatomics/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/orlyatomics/orly","description":"Orly™ Graph Database","fork":false,"url":"https://api.github.com/repos/orlyatomics/orly","forks_url":"https://api.github.com/repos/orlyatomics/orly/forks","keys_url":"https://api.github.com/repos/orlyatomics/orly/keys{/key_id}","collaborators_url":"https://api.github.com/repos/orlyatomics/orly/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/orlyatomics/orly/teams","hooks_url":"https://api.github.com/repos/orlyatomics/orly/hooks","issue_events_url":"https://api.github.com/repos/orlyatomics/orly/issues/events{/number}","events_url":"https://api.github.com/repos/orlyatomics/orly/events","assignees_url":"https://api.github.com/repos/orlyatomics/orly/assignees{/user}","branches_url":"https://api.github.com/repos/orlyatomics/orly/branches{/branch}","tags_url":"https://api.github.com/repos/orlyatomics/orly/tags","blobs_url":"https://api.github.com/repos/orlyatomics/orly/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/orlyatomics/orly/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/orlyatomics/orly/git/refs{/sha}","trees_url":"https://api.github.com/repos/orlyatomics/orly/git/trees{/sha}","statuses_url":"https://api.github.com/repos/orlyatomics/orly/statuses/{sha}","languages_url":"https://api.github.com/repos/orlyatomics/orly/languages","stargazers_url":"https://api.github.com/repos/orlyatomics/orly/stargazers","contributors_url":"https://api.github.com/repos/orlyatomics/orly/contributors","subscribers_url":"https://api.github.com/repos/orlyatomics/orly/subscribers","subscription_url":"https://api.github.com/repos/orlyatomics/orly/subscription","commits_url":"https://api.github.com/repos/orlyatomics/orly/commits{/sha}","git_commits_url":"https://api.github.com/repos/orlyatomics/orly/git/commits{/sha}","comments_url":"https://api.github.com/repos/orlyatomics/orly/comments{/number}","issue_comment_url":"https://api.github.com/repos/orlyatomics/orly/issues/comments/{number}","contents_url":"https://api.github.com/repos/orlyatomics/orly/contents/{+path}","compare_url":"https://api.github.com/repos/orlyatomics/orly/compare/{base}...{head}","merges_url":"https://api.github.com/repos/orlyatomics/orly/merges","archive_url":"https://api.github.com/repos/orlyatomics/orly/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/orlyatomics/orly/downloads","issues_url":"https://api.github.com/repos/orlyatomics/orly/issues{/number}","pulls_url":"https://api.github.com/repos/orlyatomics/orly/pulls{/number}","milestones_url":"https://api.github.com/repos/orlyatomics/orly/milestones{/number}","notifications_url":"https://api.github.com/repos/orlyatomics/orly/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/orlyatomics/orly/labels{/name}","releases_url":"https://api.github.com/repos/orlyatomics/orly/releases{/id}","created_at":"2014-04-11T18:13:15Z","updated_at":"2014-06-20T04:03:20Z","pushed_at":"2014-06-20T04:03:19Z","git_url":"git://github.com/orlyatomics/orly.git","ssh_url":"git@github.com:orlyatomics/orly.git","clone_url":"https://github.com/orlyatomics/orly.git","svn_url":"https://github.com/orlyatomics/orly","homepage":"http://orlyatomics.com/","size":7008,"stargazers_count":8,"watchers_count":8,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":12,"mirror_url":null,"open_issues_count":10,"forks":12,"open_issues":10,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/orlyatomics/orly/pulls/129"},"html":{"href":"https://github.com/orlyatomics/orly/pull/129"},"issue":{"href":"https://api.github.com/repos/orlyatomics/orly/issues/129"},"comments":{"href":"https://api.github.com/repos/orlyatomics/orly/issues/129/comments"},"review_comments":{"href":"https://api.github.com/repos/orlyatomics/orly/pulls/129/comments"},"review_comment":{"href":"https://api.github.com/repos/orlyatomics/orly/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/orlyatomics/orly/pulls/129/commits"},"statuses":{"href":"https://api.github.com/repos/orlyatomics/orly/statuses/badaacbdf44596a00349bd1ca4b0e142f8685ae2"}}}}