{"action":"created","comment":{"url":"https://api.github.com/repos/serge-sans-paille/talks/pulls/comments/28846863","id":28846863,"diff_hunk":"@@ -0,0 +1,212 @@\n+#include <iostream>\n+#include <tuple>\n+#include <vector>\n+\n+template<size_t ...>\n+struct seq { };\n+\n+template<size_t N, size_t ...S>\n+struct gens : gens<N-1, N-1, S...> { };\n+\n+template<size_t ...S>\n+struct gens<0, S...> {\n+typedef seq<S...> type;\n+};\n+\n+template <class ObjData>\n+struct ObjAccessVertical: public ObjData\n+{\n+\tusing ObjData::ObjData;\n+\n+\ttemplate <size_t I>\n+\tauto& get_data()\n+\t{\n+\t\treturn std::get<I>(static_cast<ObjData&>(*this));\n+\t}\n+\n+\ttemplate <size_t I>\n+\tauto const& get_data() const\n+\t{\n+\t\treturn std::get<I>(static_cast<ObjData const&>(*this));\n+\t}\n+};\n+\n+template <template <class Storage> class Obj, class... Args>\n+struct ObjStorageVertical: public std::vector<Obj<ObjAccessVertical<std::tuple<Args...>>>>\n+{ };\n+\n+template <class Storage>\n+struct ObjAccessHorizontal\n+{\n+\tObjAccessHorizontal(Storage* s, size_t i):\n+\t\tstorage(s),\n+\t\tidx(i)\n+\t{ }\n+\n+\tObjAccessHorizontal(ObjAccessHorizontal const& o):\n+\t\tstorage(o.storage),\n+\t\tidx(o.idx)\n+\t{ }\n+\n+\ttemplate <size_t I>\n+\tauto& get_data()\n+\t{\n+\t\treturn std::get<I>(*storage)[idx];\n+\t}\n+\n+\ttemplate <size_t I>\n+\tauto const& get_data() const\n+\t{\n+\t\treturn std::get<I>(*storage)[idx];\n+\t}\n+\n+\tStorage* storage;\n+\tsize_t idx;\n+};\n+\n+template <template <class Storage> class Obj, class... Args>\n+struct ObjStorageHorizontal\n+{\n+\ttypedef std::tuple<std::vector<Args>...> storage_type;\n+\ttypedef Obj<ObjAccessHorizontal<storage_type>> obj_type;\n+\n+\tstatic typename gens<sizeof...(Args)>::type args_ns;\n+\n+\tstruct iterator\n+\t{\n+\t\titerator() = default;\n+\n+\t\tobj_type& operator*() { return _o; }\n+\t\tobj_type& operator->() { return _o; }\n+\n+\n+\t\tbool operator==(iterator const& v) const\n+\t\t{\n+\t\t\treturn _o.idx == v._o.idx && _o.storage == v._o.storage;\n+\t\t}\n+\n+\t\tbool operator!=(iterator const& v) const\n+\t\t{\n+\t\t\treturn !(*this == v);\n+\t\t}\n+\n+\t\titerator& operator++(int)\n+\t\t{\n+\t\t\titerator ret(*this);\n+\t\t\t++_o.idx;\n+\t\t\treturn ret;\n+\t\t}\n+\n+\t\titerator& operator++()\n+\t\t{\n+\t\t\t++_o.idx;\n+\t\t\treturn *this;\n+\t\t}\n+\n+\t\tobj_type _o;\n+\t};\n+\n+\tvoid emplace_back(Args&& ... args)\n+\t{\n+\t\templace_back(std::forward<Args>(args)..., args_ns);\n+\t}\n+\n+\ttemplate <size_t... I>\n+\tvoid emplace_back(Args&& ... args, seq<I...>)\n+\t{\n+\t\tstd::initializer_list<int> li = {(std::get<I>(_storage).emplace_back(std::forward<Args>(args)), 1)...};\n+\t\t(void)li;\n+\t}\n+\n+\tvoid reserve(size_t n)\n+\t{\n+\t\treserve(n, args_ns);\n+\t}\n+\n+\ttemplate <size_t... I>\n+\tvoid reserve(size_t n, seq<I...>)\n+\t{\n+\t\tstd::initializer_list<int> li = {(std::get<I>(_storage).reserve(n), 1)...};\n+\t\t(void)li;\n+\t}\n+\n+\titerator begin()\n+\t{\n+\t\treturn iterator{obj_type{&_storage, 0}};\n+\t}\n+\n+\titerator end()\n+\t{\n+\t\treturn iterator{obj_type{&_storage, std::get<0>(_storage).size()}};\n+\t}\n+\n+\tobj_type front() { return *begin(); }\n+\n+private:\n+\tstorage_type _storage;\n+};\n+\n+template <size_t I, class O>\n+auto& get_data(O& o)\n+{\n+\treturn o.template get_data<I>();\n+}\n+\n+template <size_t I, class O>\n+auto const& get_data(O const& o)\n+{\n+\treturn o.template get_data<I>();\n+}\n+\n+// Public interface\n+//\n+\n+template <class Accessor>\n+struct Obj: public Accessor\n+{\n+\tusing Accessor::Accessor;\n+\n+\tvoid dump()\n+\t{\n+\t\tstd::cout << name() << \" is \" << age() << std::endl;\n+\t}\n+\n+\tint& age() { return get_data<0>(*this); }\n+\tstd::string& name() { return get_data<1>(*this); }\n+\n+\tint age() const { return get_data<0>(*this); }\n+\tstd::string name() const { return get_data<1>(*this); }\n+};\n+\n+\n+template <class T>\n+void test(T& s)\n+{\n+\ts.reserve(4);\n+\ts.emplace_back(1, \"blabla\");\n+\ts.emplace_back(2, \"blabla\");\n+\ts.emplace_back(3, \"blabla\");\n+\ts.emplace_back(4, \"blabla\");\n+\ts.front().dump();\n+\ts.front().age() = 10;\n+\tfor (auto& o: s) {\n+\t\to.dump();\n+\t\to.name() = \"test\";\n+\t}\n+\tfor (auto& o: s) {\n+\t\to.dump();\n+\t}\n+}\n+\n+int main()\n+{\n+\tObjStorageVertical<Obj, int, std::string> s;\n+\ttest(s);\n+\n+\tstd::cout << \"--\" << std::endl;\n+\n+\tObjStorageHorizontal<Obj, int, std::string> s2;\n+\ttest(s2);\n+\n+\treturn 0;","path":"cxx-idioms/vertical_or_horizontal_storage.cpp","position":211,"original_position":211,"commit_id":"55dce622053efa197c6eccf590dc0c9261600114","original_commit_id":"55dce622053efa197c6eccf590dc0c9261600114","user":{"login":"aguinet","id":1874053,"avatar_url":"https://avatars.githubusercontent.com/u/1874053?v=3","gravatar_id":"","url":"https://api.github.com/users/aguinet","html_url":"https://github.com/aguinet","followers_url":"https://api.github.com/users/aguinet/followers","following_url":"https://api.github.com/users/aguinet/following{/other_user}","gists_url":"https://api.github.com/users/aguinet/gists{/gist_id}","starred_url":"https://api.github.com/users/aguinet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aguinet/subscriptions","organizations_url":"https://api.github.com/users/aguinet/orgs","repos_url":"https://api.github.com/users/aguinet/repos","events_url":"https://api.github.com/users/aguinet/events{/privacy}","received_events_url":"https://api.github.com/users/aguinet/received_events","type":"User","site_admin":false},"body":"ouais :/ je me disais qu'on pourrait extraire juste certains idioms, genre le make_sequence à la main et version C++14, et globalement jouer avec des listes de types variadics. J'ai 2/3 idées en tête du coup!","created_at":"2015-04-22T06:08:30Z","updated_at":"2015-04-22T06:08:30Z","html_url":"https://github.com/serge-sans-paille/talks/pull/1#discussion_r28846863","pull_request_url":"https://api.github.com/repos/serge-sans-paille/talks/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/serge-sans-paille/talks/pulls/comments/28846863"},"html":{"href":"https://github.com/serge-sans-paille/talks/pull/1#discussion_r28846863"},"pull_request":{"href":"https://api.github.com/repos/serge-sans-paille/talks/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/serge-sans-paille/talks/pulls/1","id":33811917,"html_url":"https://github.com/serge-sans-paille/talks/pull/1","diff_url":"https://github.com/serge-sans-paille/talks/pull/1.diff","patch_url":"https://github.com/serge-sans-paille/talks/pull/1.patch","issue_url":"https://api.github.com/repos/serge-sans-paille/talks/issues/1","number":1,"state":"open","locked":false,"title":"3 new + some changes","user":{"login":"aguinet","id":1874053,"avatar_url":"https://avatars.githubusercontent.com/u/1874053?v=3","gravatar_id":"","url":"https://api.github.com/users/aguinet","html_url":"https://github.com/aguinet","followers_url":"https://api.github.com/users/aguinet/followers","following_url":"https://api.github.com/users/aguinet/following{/other_user}","gists_url":"https://api.github.com/users/aguinet/gists{/gist_id}","starred_url":"https://api.github.com/users/aguinet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aguinet/subscriptions","organizations_url":"https://api.github.com/users/aguinet/orgs","repos_url":"https://api.github.com/users/aguinet/repos","events_url":"https://api.github.com/users/aguinet/events{/privacy}","received_events_url":"https://api.github.com/users/aguinet/received_events","type":"User","site_admin":false},"body":"I'm not sure about the \"vertical_or_horizontal_storage\" because the\r\nimplementation is a bit verbose. Anyway, the usage is quite \"simple\",\r\nand that's something I wanted to do for a long time :) I think there's a\r\nway to make it shorter, if you have idea!","created_at":"2015-04-21T22:58:16Z","updated_at":"2015-04-22T06:08:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"61c809d7452a5edb1bb06f6c6bdeaf1a0721a7be","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/serge-sans-paille/talks/pulls/1/commits","review_comments_url":"https://api.github.com/repos/serge-sans-paille/talks/pulls/1/comments","review_comment_url":"https://api.github.com/repos/serge-sans-paille/talks/pulls/comments{/number}","comments_url":"https://api.github.com/repos/serge-sans-paille/talks/issues/1/comments","statuses_url":"https://api.github.com/repos/serge-sans-paille/talks/statuses/55dce622053efa197c6eccf590dc0c9261600114","head":{"label":"aguinet:cxx-idioms","ref":"cxx-idioms","sha":"55dce622053efa197c6eccf590dc0c9261600114","user":{"login":"aguinet","id":1874053,"avatar_url":"https://avatars.githubusercontent.com/u/1874053?v=3","gravatar_id":"","url":"https://api.github.com/users/aguinet","html_url":"https://github.com/aguinet","followers_url":"https://api.github.com/users/aguinet/followers","following_url":"https://api.github.com/users/aguinet/following{/other_user}","gists_url":"https://api.github.com/users/aguinet/gists{/gist_id}","starred_url":"https://api.github.com/users/aguinet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aguinet/subscriptions","organizations_url":"https://api.github.com/users/aguinet/orgs","repos_url":"https://api.github.com/users/aguinet/repos","events_url":"https://api.github.com/users/aguinet/events{/privacy}","received_events_url":"https://api.github.com/users/aguinet/received_events","type":"User","site_admin":false},"repo":{"id":34353050,"name":"serge-talks","full_name":"aguinet/serge-talks","owner":{"login":"aguinet","id":1874053,"avatar_url":"https://avatars.githubusercontent.com/u/1874053?v=3","gravatar_id":"","url":"https://api.github.com/users/aguinet","html_url":"https://github.com/aguinet","followers_url":"https://api.github.com/users/aguinet/followers","following_url":"https://api.github.com/users/aguinet/following{/other_user}","gists_url":"https://api.github.com/users/aguinet/gists{/gist_id}","starred_url":"https://api.github.com/users/aguinet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aguinet/subscriptions","organizations_url":"https://api.github.com/users/aguinet/orgs","repos_url":"https://api.github.com/users/aguinet/repos","events_url":"https://api.github.com/users/aguinet/events{/privacy}","received_events_url":"https://api.github.com/users/aguinet/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aguinet/serge-talks","description":"serge sans paille's talks","fork":true,"url":"https://api.github.com/repos/aguinet/serge-talks","forks_url":"https://api.github.com/repos/aguinet/serge-talks/forks","keys_url":"https://api.github.com/repos/aguinet/serge-talks/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aguinet/serge-talks/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aguinet/serge-talks/teams","hooks_url":"https://api.github.com/repos/aguinet/serge-talks/hooks","issue_events_url":"https://api.github.com/repos/aguinet/serge-talks/issues/events{/number}","events_url":"https://api.github.com/repos/aguinet/serge-talks/events","assignees_url":"https://api.github.com/repos/aguinet/serge-talks/assignees{/user}","branches_url":"https://api.github.com/repos/aguinet/serge-talks/branches{/branch}","tags_url":"https://api.github.com/repos/aguinet/serge-talks/tags","blobs_url":"https://api.github.com/repos/aguinet/serge-talks/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aguinet/serge-talks/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aguinet/serge-talks/git/refs{/sha}","trees_url":"https://api.github.com/repos/aguinet/serge-talks/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aguinet/serge-talks/statuses/{sha}","languages_url":"https://api.github.com/repos/aguinet/serge-talks/languages","stargazers_url":"https://api.github.com/repos/aguinet/serge-talks/stargazers","contributors_url":"https://api.github.com/repos/aguinet/serge-talks/contributors","subscribers_url":"https://api.github.com/repos/aguinet/serge-talks/subscribers","subscription_url":"https://api.github.com/repos/aguinet/serge-talks/subscription","commits_url":"https://api.github.com/repos/aguinet/serge-talks/commits{/sha}","git_commits_url":"https://api.github.com/repos/aguinet/serge-talks/git/commits{/sha}","comments_url":"https://api.github.com/repos/aguinet/serge-talks/comments{/number}","issue_comment_url":"https://api.github.com/repos/aguinet/serge-talks/issues/comments{/number}","contents_url":"https://api.github.com/repos/aguinet/serge-talks/contents/{+path}","compare_url":"https://api.github.com/repos/aguinet/serge-talks/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aguinet/serge-talks/merges","archive_url":"https://api.github.com/repos/aguinet/serge-talks/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aguinet/serge-talks/downloads","issues_url":"https://api.github.com/repos/aguinet/serge-talks/issues{/number}","pulls_url":"https://api.github.com/repos/aguinet/serge-talks/pulls{/number}","milestones_url":"https://api.github.com/repos/aguinet/serge-talks/milestones{/number}","notifications_url":"https://api.github.com/repos/aguinet/serge-talks/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aguinet/serge-talks/labels{/name}","releases_url":"https://api.github.com/repos/aguinet/serge-talks/releases{/id}","created_at":"2015-04-21T21:26:02Z","updated_at":"2015-04-21T21:26:59Z","pushed_at":"2015-04-21T22:57:52Z","git_url":"git://github.com/aguinet/serge-talks.git","ssh_url":"git@github.com:aguinet/serge-talks.git","clone_url":"https://github.com/aguinet/serge-talks.git","svn_url":"https://github.com/aguinet/serge-talks","homepage":null,"size":6184,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"serge-sans-paille:cxx-idioms","ref":"cxx-idioms","sha":"d7a47eae9cf9b987afb5519ce6dbe9d1b7b35c28","user":{"login":"serge-sans-paille","id":863807,"avatar_url":"https://avatars.githubusercontent.com/u/863807?v=3","gravatar_id":"","url":"https://api.github.com/users/serge-sans-paille","html_url":"https://github.com/serge-sans-paille","followers_url":"https://api.github.com/users/serge-sans-paille/followers","following_url":"https://api.github.com/users/serge-sans-paille/following{/other_user}","gists_url":"https://api.github.com/users/serge-sans-paille/gists{/gist_id}","starred_url":"https://api.github.com/users/serge-sans-paille/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serge-sans-paille/subscriptions","organizations_url":"https://api.github.com/users/serge-sans-paille/orgs","repos_url":"https://api.github.com/users/serge-sans-paille/repos","events_url":"https://api.github.com/users/serge-sans-paille/events{/privacy}","received_events_url":"https://api.github.com/users/serge-sans-paille/received_events","type":"User","site_admin":false},"repo":{"id":21819405,"name":"talks","full_name":"serge-sans-paille/talks","owner":{"login":"serge-sans-paille","id":863807,"avatar_url":"https://avatars.githubusercontent.com/u/863807?v=3","gravatar_id":"","url":"https://api.github.com/users/serge-sans-paille","html_url":"https://github.com/serge-sans-paille","followers_url":"https://api.github.com/users/serge-sans-paille/followers","following_url":"https://api.github.com/users/serge-sans-paille/following{/other_user}","gists_url":"https://api.github.com/users/serge-sans-paille/gists{/gist_id}","starred_url":"https://api.github.com/users/serge-sans-paille/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serge-sans-paille/subscriptions","organizations_url":"https://api.github.com/users/serge-sans-paille/orgs","repos_url":"https://api.github.com/users/serge-sans-paille/repos","events_url":"https://api.github.com/users/serge-sans-paille/events{/privacy}","received_events_url":"https://api.github.com/users/serge-sans-paille/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/serge-sans-paille/talks","description":"serge sans paille's talks","fork":false,"url":"https://api.github.com/repos/serge-sans-paille/talks","forks_url":"https://api.github.com/repos/serge-sans-paille/talks/forks","keys_url":"https://api.github.com/repos/serge-sans-paille/talks/keys{/key_id}","collaborators_url":"https://api.github.com/repos/serge-sans-paille/talks/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/serge-sans-paille/talks/teams","hooks_url":"https://api.github.com/repos/serge-sans-paille/talks/hooks","issue_events_url":"https://api.github.com/repos/serge-sans-paille/talks/issues/events{/number}","events_url":"https://api.github.com/repos/serge-sans-paille/talks/events","assignees_url":"https://api.github.com/repos/serge-sans-paille/talks/assignees{/user}","branches_url":"https://api.github.com/repos/serge-sans-paille/talks/branches{/branch}","tags_url":"https://api.github.com/repos/serge-sans-paille/talks/tags","blobs_url":"https://api.github.com/repos/serge-sans-paille/talks/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/serge-sans-paille/talks/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/serge-sans-paille/talks/git/refs{/sha}","trees_url":"https://api.github.com/repos/serge-sans-paille/talks/git/trees{/sha}","statuses_url":"https://api.github.com/repos/serge-sans-paille/talks/statuses/{sha}","languages_url":"https://api.github.com/repos/serge-sans-paille/talks/languages","stargazers_url":"https://api.github.com/repos/serge-sans-paille/talks/stargazers","contributors_url":"https://api.github.com/repos/serge-sans-paille/talks/contributors","subscribers_url":"https://api.github.com/repos/serge-sans-paille/talks/subscribers","subscription_url":"https://api.github.com/repos/serge-sans-paille/talks/subscription","commits_url":"https://api.github.com/repos/serge-sans-paille/talks/commits{/sha}","git_commits_url":"https://api.github.com/repos/serge-sans-paille/talks/git/commits{/sha}","comments_url":"https://api.github.com/repos/serge-sans-paille/talks/comments{/number}","issue_comment_url":"https://api.github.com/repos/serge-sans-paille/talks/issues/comments{/number}","contents_url":"https://api.github.com/repos/serge-sans-paille/talks/contents/{+path}","compare_url":"https://api.github.com/repos/serge-sans-paille/talks/compare/{base}...{head}","merges_url":"https://api.github.com/repos/serge-sans-paille/talks/merges","archive_url":"https://api.github.com/repos/serge-sans-paille/talks/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/serge-sans-paille/talks/downloads","issues_url":"https://api.github.com/repos/serge-sans-paille/talks/issues{/number}","pulls_url":"https://api.github.com/repos/serge-sans-paille/talks/pulls{/number}","milestones_url":"https://api.github.com/repos/serge-sans-paille/talks/milestones{/number}","notifications_url":"https://api.github.com/repos/serge-sans-paille/talks/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/serge-sans-paille/talks/labels{/name}","releases_url":"https://api.github.com/repos/serge-sans-paille/talks/releases{/id}","created_at":"2014-07-14T12:55:01Z","updated_at":"2015-01-28T09:40:45Z","pushed_at":"2015-04-21T22:58:17Z","git_url":"git://github.com/serge-sans-paille/talks.git","ssh_url":"git@github.com:serge-sans-paille/talks.git","clone_url":"https://github.com/serge-sans-paille/talks.git","svn_url":"https://github.com/serge-sans-paille/talks","homepage":null,"size":6184,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/serge-sans-paille/talks/pulls/1"},"html":{"href":"https://github.com/serge-sans-paille/talks/pull/1"},"issue":{"href":"https://api.github.com/repos/serge-sans-paille/talks/issues/1"},"comments":{"href":"https://api.github.com/repos/serge-sans-paille/talks/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/serge-sans-paille/talks/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/serge-sans-paille/talks/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/serge-sans-paille/talks/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/serge-sans-paille/talks/statuses/55dce622053efa197c6eccf590dc0c9261600114"}}}}