{"action":"created","comment":{"url":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/comments/238331924","pull_request_review_id":180846656,"id":238331924,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzODMzMTkyNA==","diff_hunk":"@@ -75,10 +75,49 @@ namespace shogun\n {\n \ttypedef std::unordered_map<std::type_index, TYPE> typemap;\n \n+\tnamespace type_internal\n+\t{\n+\t\tstd::string demangled_type(const char* name)","path":"src/shogun/lib/type_case.h","position":80,"original_position":6,"commit_id":"48332ece3915dd27ac60ec86890913d816e70e03","original_commit_id":"48332ece3915dd27ac60ec86890913d816e70e03","user":{"login":"karlnapf","id":699071,"node_id":"MDQ6VXNlcjY5OTA3MQ==","avatar_url":"https://avatars0.githubusercontent.com/u/699071?v=4","gravatar_id":"","url":"https://api.github.com/users/karlnapf","html_url":"https://github.com/karlnapf","followers_url":"https://api.github.com/users/karlnapf/followers","following_url":"https://api.github.com/users/karlnapf/following{/other_user}","gists_url":"https://api.github.com/users/karlnapf/gists{/gist_id}","starred_url":"https://api.github.com/users/karlnapf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karlnapf/subscriptions","organizations_url":"https://api.github.com/users/karlnapf/orgs","repos_url":"https://api.github.com/users/karlnapf/repos","events_url":"https://api.github.com/users/karlnapf/events{/privacy}","received_events_url":"https://api.github.com/users/karlnapf/received_events","type":"User","site_admin":false},"body":"wait, didn't we have a function like this somewhere already?","created_at":"2018-12-03T16:10:21Z","updated_at":"2018-12-03T16:10:21Z","html_url":"https://github.com/shogun-toolbox/shogun/pull/4426#discussion_r238331924","pull_request_url":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/4426","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/comments/238331924"},"html":{"href":"https://github.com/shogun-toolbox/shogun/pull/4426#discussion_r238331924"},"pull_request":{"href":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/4426"}}},"pull_request":{"url":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/4426","id":234701408,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM0NzAxNDA4","html_url":"https://github.com/shogun-toolbox/shogun/pull/4426","diff_url":"https://github.com/shogun-toolbox/shogun/pull/4426.diff","patch_url":"https://github.com/shogun-toolbox/shogun/pull/4426.patch","issue_url":"https://api.github.com/repos/shogun-toolbox/shogun/issues/4426","number":4426,"state":"open","locked":false,"title":"Check type of Any for casting","user":{"login":"gf712","id":12395516,"node_id":"MDQ6VXNlcjEyMzk1NTE2","avatar_url":"https://avatars0.githubusercontent.com/u/12395516?v=4","gravatar_id":"","url":"https://api.github.com/users/gf712","html_url":"https://github.com/gf712","followers_url":"https://api.github.com/users/gf712/followers","following_url":"https://api.github.com/users/gf712/following{/other_user}","gists_url":"https://api.github.com/users/gf712/gists{/gist_id}","starred_url":"https://api.github.com/users/gf712/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gf712/subscriptions","organizations_url":"https://api.github.com/users/gf712/orgs","repos_url":"https://api.github.com/users/gf712/repos","events_url":"https://api.github.com/users/gf712/events{/privacy}","received_events_url":"https://api.github.com/users/gf712/received_events","type":"User","site_admin":false},"body":"To cast Any back to its original type we need to check each type used in shogun before casting.\r\nI implemented a function that does this check and then executes a lambda when it finds the right type.\r\nIt still needs some work:\r\n- [x] handle errors\r\n- [x] add more type maps\r\n- [x] ~~maybe add some sort of check for the lambda, i.e. does it have the expected signature?~~\r\n- [x] should it be void rather than return `int`? The `int` was just initially used for debugging.\r\n\r\nExample usage:\r\n\r\n```\r\n#include <iostream>\r\n#include <shogun/base/init.h>\r\n#include <shogun/io/SGIO.h>\r\n#include <shogun/lib/type_case.h>\r\n\r\nusing namespace shogun;\r\n\r\nint main() {\r\n\r\n\tinit_shogun();\r\n\r\n\tint a = 2.0;\r\n\tAny any = make_any(a);\r\n\r\n        // declare a lambda that is executed when the original type is found\r\n        // needs this signature\r\n        // the [&any] captures any by reference\r\n\tauto found_it_lambda = [&any](auto type) {\r\n\t\tstd::cout << \"It's a \" << demangled_type<decltype(type)>() << std::endl;\r\n\t\tstd::cout << \"Value \" << any_cast<decltype(type)>(any) << std::endl;\r\n\t};\r\n\r\n\ttry {\r\n\t\tfor_each_type(any, all_types, found_it_lambda);\r\n\t}\r\n\tcatch (ShogunException &msg) {\r\n\t\tstd::cout << msg.what() << std::endl;\r\n\t}\r\n\r\n\ttry {\r\n\tfor_each_type(any, real_types, found_it_lambda);\r\n\t}\r\n\tcatch (ShogunException &m) {\r\n\t\tstd::cout << m.what() << std::endl;\r\n\t}\r\n}\r\n```\r\nExpected output:\r\n```\r\nIt's a int\r\nValue 2\r\n[ERROR] In file /Users/ghoben/anaconda3/include/shogun/lib/type_case.h line 197: Type int is not part of <long double, double, float>\r\n```","created_at":"2018-11-29T16:24:25Z","updated_at":"2018-12-03T16:10:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1b3ce46c04f7998e61d7950cd00e10f93a0e5586","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/4426/commits","review_comments_url":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/4426/comments","review_comment_url":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/comments{/number}","comments_url":"https://api.github.com/repos/shogun-toolbox/shogun/issues/4426/comments","statuses_url":"https://api.github.com/repos/shogun-toolbox/shogun/statuses/48332ece3915dd27ac60ec86890913d816e70e03","head":{"label":"gf712:feature/check_type_macros","ref":"feature/check_type_macros","sha":"48332ece3915dd27ac60ec86890913d816e70e03","user":{"login":"gf712","id":12395516,"node_id":"MDQ6VXNlcjEyMzk1NTE2","avatar_url":"https://avatars0.githubusercontent.com/u/12395516?v=4","gravatar_id":"","url":"https://api.github.com/users/gf712","html_url":"https://github.com/gf712","followers_url":"https://api.github.com/users/gf712/followers","following_url":"https://api.github.com/users/gf712/following{/other_user}","gists_url":"https://api.github.com/users/gf712/gists{/gist_id}","starred_url":"https://api.github.com/users/gf712/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gf712/subscriptions","organizations_url":"https://api.github.com/users/gf712/orgs","repos_url":"https://api.github.com/users/gf712/repos","events_url":"https://api.github.com/users/gf712/events{/privacy}","received_events_url":"https://api.github.com/users/gf712/received_events","type":"User","site_admin":false},"repo":{"id":153130355,"node_id":"MDEwOlJlcG9zaXRvcnkxNTMxMzAzNTU=","name":"shogun","full_name":"gf712/shogun","private":false,"owner":{"login":"gf712","id":12395516,"node_id":"MDQ6VXNlcjEyMzk1NTE2","avatar_url":"https://avatars0.githubusercontent.com/u/12395516?v=4","gravatar_id":"","url":"https://api.github.com/users/gf712","html_url":"https://github.com/gf712","followers_url":"https://api.github.com/users/gf712/followers","following_url":"https://api.github.com/users/gf712/following{/other_user}","gists_url":"https://api.github.com/users/gf712/gists{/gist_id}","starred_url":"https://api.github.com/users/gf712/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gf712/subscriptions","organizations_url":"https://api.github.com/users/gf712/orgs","repos_url":"https://api.github.com/users/gf712/repos","events_url":"https://api.github.com/users/gf712/events{/privacy}","received_events_url":"https://api.github.com/users/gf712/received_events","type":"User","site_admin":false},"html_url":"https://github.com/gf712/shogun","description":"Shōgun","fork":true,"url":"https://api.github.com/repos/gf712/shogun","forks_url":"https://api.github.com/repos/gf712/shogun/forks","keys_url":"https://api.github.com/repos/gf712/shogun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gf712/shogun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gf712/shogun/teams","hooks_url":"https://api.github.com/repos/gf712/shogun/hooks","issue_events_url":"https://api.github.com/repos/gf712/shogun/issues/events{/number}","events_url":"https://api.github.com/repos/gf712/shogun/events","assignees_url":"https://api.github.com/repos/gf712/shogun/assignees{/user}","branches_url":"https://api.github.com/repos/gf712/shogun/branches{/branch}","tags_url":"https://api.github.com/repos/gf712/shogun/tags","blobs_url":"https://api.github.com/repos/gf712/shogun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gf712/shogun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gf712/shogun/git/refs{/sha}","trees_url":"https://api.github.com/repos/gf712/shogun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gf712/shogun/statuses/{sha}","languages_url":"https://api.github.com/repos/gf712/shogun/languages","stargazers_url":"https://api.github.com/repos/gf712/shogun/stargazers","contributors_url":"https://api.github.com/repos/gf712/shogun/contributors","subscribers_url":"https://api.github.com/repos/gf712/shogun/subscribers","subscription_url":"https://api.github.com/repos/gf712/shogun/subscription","commits_url":"https://api.github.com/repos/gf712/shogun/commits{/sha}","git_commits_url":"https://api.github.com/repos/gf712/shogun/git/commits{/sha}","comments_url":"https://api.github.com/repos/gf712/shogun/comments{/number}","issue_comment_url":"https://api.github.com/repos/gf712/shogun/issues/comments{/number}","contents_url":"https://api.github.com/repos/gf712/shogun/contents/{+path}","compare_url":"https://api.github.com/repos/gf712/shogun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gf712/shogun/merges","archive_url":"https://api.github.com/repos/gf712/shogun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gf712/shogun/downloads","issues_url":"https://api.github.com/repos/gf712/shogun/issues{/number}","pulls_url":"https://api.github.com/repos/gf712/shogun/pulls{/number}","milestones_url":"https://api.github.com/repos/gf712/shogun/milestones{/number}","notifications_url":"https://api.github.com/repos/gf712/shogun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gf712/shogun/labels{/name}","releases_url":"https://api.github.com/repos/gf712/shogun/releases{/id}","deployments_url":"https://api.github.com/repos/gf712/shogun/deployments","created_at":"2018-10-15T14:42:44Z","updated_at":"2018-11-16T14:23:01Z","pushed_at":"2018-12-03T14:30:17Z","git_url":"git://github.com/gf712/shogun.git","ssh_url":"git@github.com:gf712/shogun.git","clone_url":"https://github.com/gf712/shogun.git","svn_url":"https://github.com/gf712/shogun","homepage":"http://shogun.ml","size":65725,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"shogun-toolbox:develop","ref":"develop","sha":"b5345f5771e30e6ddec0a7c456f58b9f0b071868","user":{"login":"shogun-toolbox","id":690673,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY5MDY3Mw==","avatar_url":"https://avatars1.githubusercontent.com/u/690673?v=4","gravatar_id":"","url":"https://api.github.com/users/shogun-toolbox","html_url":"https://github.com/shogun-toolbox","followers_url":"https://api.github.com/users/shogun-toolbox/followers","following_url":"https://api.github.com/users/shogun-toolbox/following{/other_user}","gists_url":"https://api.github.com/users/shogun-toolbox/gists{/gist_id}","starred_url":"https://api.github.com/users/shogun-toolbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shogun-toolbox/subscriptions","organizations_url":"https://api.github.com/users/shogun-toolbox/orgs","repos_url":"https://api.github.com/users/shogun-toolbox/repos","events_url":"https://api.github.com/users/shogun-toolbox/events{/privacy}","received_events_url":"https://api.github.com/users/shogun-toolbox/received_events","type":"Organization","site_admin":false},"repo":{"id":1555094,"node_id":"MDEwOlJlcG9zaXRvcnkxNTU1MDk0","name":"shogun","full_name":"shogun-toolbox/shogun","private":false,"owner":{"login":"shogun-toolbox","id":690673,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY5MDY3Mw==","avatar_url":"https://avatars1.githubusercontent.com/u/690673?v=4","gravatar_id":"","url":"https://api.github.com/users/shogun-toolbox","html_url":"https://github.com/shogun-toolbox","followers_url":"https://api.github.com/users/shogun-toolbox/followers","following_url":"https://api.github.com/users/shogun-toolbox/following{/other_user}","gists_url":"https://api.github.com/users/shogun-toolbox/gists{/gist_id}","starred_url":"https://api.github.com/users/shogun-toolbox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shogun-toolbox/subscriptions","organizations_url":"https://api.github.com/users/shogun-toolbox/orgs","repos_url":"https://api.github.com/users/shogun-toolbox/repos","events_url":"https://api.github.com/users/shogun-toolbox/events{/privacy}","received_events_url":"https://api.github.com/users/shogun-toolbox/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/shogun-toolbox/shogun","description":"Shōgun","fork":false,"url":"https://api.github.com/repos/shogun-toolbox/shogun","forks_url":"https://api.github.com/repos/shogun-toolbox/shogun/forks","keys_url":"https://api.github.com/repos/shogun-toolbox/shogun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shogun-toolbox/shogun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shogun-toolbox/shogun/teams","hooks_url":"https://api.github.com/repos/shogun-toolbox/shogun/hooks","issue_events_url":"https://api.github.com/repos/shogun-toolbox/shogun/issues/events{/number}","events_url":"https://api.github.com/repos/shogun-toolbox/shogun/events","assignees_url":"https://api.github.com/repos/shogun-toolbox/shogun/assignees{/user}","branches_url":"https://api.github.com/repos/shogun-toolbox/shogun/branches{/branch}","tags_url":"https://api.github.com/repos/shogun-toolbox/shogun/tags","blobs_url":"https://api.github.com/repos/shogun-toolbox/shogun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shogun-toolbox/shogun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shogun-toolbox/shogun/git/refs{/sha}","trees_url":"https://api.github.com/repos/shogun-toolbox/shogun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shogun-toolbox/shogun/statuses/{sha}","languages_url":"https://api.github.com/repos/shogun-toolbox/shogun/languages","stargazers_url":"https://api.github.com/repos/shogun-toolbox/shogun/stargazers","contributors_url":"https://api.github.com/repos/shogun-toolbox/shogun/contributors","subscribers_url":"https://api.github.com/repos/shogun-toolbox/shogun/subscribers","subscription_url":"https://api.github.com/repos/shogun-toolbox/shogun/subscription","commits_url":"https://api.github.com/repos/shogun-toolbox/shogun/commits{/sha}","git_commits_url":"https://api.github.com/repos/shogun-toolbox/shogun/git/commits{/sha}","comments_url":"https://api.github.com/repos/shogun-toolbox/shogun/comments{/number}","issue_comment_url":"https://api.github.com/repos/shogun-toolbox/shogun/issues/comments{/number}","contents_url":"https://api.github.com/repos/shogun-toolbox/shogun/contents/{+path}","compare_url":"https://api.github.com/repos/shogun-toolbox/shogun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shogun-toolbox/shogun/merges","archive_url":"https://api.github.com/repos/shogun-toolbox/shogun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shogun-toolbox/shogun/downloads","issues_url":"https://api.github.com/repos/shogun-toolbox/shogun/issues{/number}","pulls_url":"https://api.github.com/repos/shogun-toolbox/shogun/pulls{/number}","milestones_url":"https://api.github.com/repos/shogun-toolbox/shogun/milestones{/number}","notifications_url":"https://api.github.com/repos/shogun-toolbox/shogun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shogun-toolbox/shogun/labels{/name}","releases_url":"https://api.github.com/repos/shogun-toolbox/shogun/releases{/id}","deployments_url":"https://api.github.com/repos/shogun-toolbox/shogun/deployments","created_at":"2011-04-01T10:44:32Z","updated_at":"2018-12-03T13:29:33Z","pushed_at":"2018-12-03T14:30:19Z","git_url":"git://github.com/shogun-toolbox/shogun.git","ssh_url":"git@github.com:shogun-toolbox/shogun.git","clone_url":"https://github.com/shogun-toolbox/shogun.git","svn_url":"https://github.com/shogun-toolbox/shogun","homepage":"http://shogun.ml","size":65689,"stargazers_count":2275,"watchers_count":2275,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":883,"mirror_url":null,"archived":false,"open_issues_count":546,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":883,"open_issues":546,"watchers":2275,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/4426"},"html":{"href":"https://github.com/shogun-toolbox/shogun/pull/4426"},"issue":{"href":"https://api.github.com/repos/shogun-toolbox/shogun/issues/4426"},"comments":{"href":"https://api.github.com/repos/shogun-toolbox/shogun/issues/4426/comments"},"review_comments":{"href":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/4426/comments"},"review_comment":{"href":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/shogun-toolbox/shogun/pulls/4426/commits"},"statuses":{"href":"https://api.github.com/repos/shogun-toolbox/shogun/statuses/48332ece3915dd27ac60ec86890913d816e70e03"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"karlnapf"}}