{"id":1024,"date":"2015-02-20T11:08:50","date_gmt":"2015-02-20T19:08:50","guid":{"rendered":"http:\/\/www.elbeno.com\/blog\/?p=1024"},"modified":"2015-06-30T21:16:39","modified_gmt":"2015-07-01T04:16:39","slug":"vs2010-woes-tuples-as-map-keys","status":"publish","type":"post","link":"https:\/\/www.elbeno.com\/blog\/?p=1024","title":{"rendered":"VS2010 woes: tuples as map keys"},"content":{"rendered":"<p>Another day, another compiler\/library bug. If you&#8217;re unfortunate enough to still be using Visual Studio 2010, don&#8217;t use tuples as map keys.<\/p>\n<pre lang=\"cpp\">\r\n#include <map>\r\n#include <tuple>\r\n#include <utility>\r\n\r\nusing namespace std;\r\n\r\ntypedef tuple<int *, int> FooT;\r\ntypedef map<FooT, int> MapT;\r\n\r\nint main(int, char*[])\r\n{\r\n  MapT m;\r\n\r\n  \/\/ put a value in the map\r\n  {\r\n    FooT f(nullptr, 0);\r\n    m[f] = 1337;\r\n  }\r\n\r\n  \/\/ retrieve a value\r\n  int s;\r\n  {\r\n    FooT f(nullptr, 0);\r\n    auto i = m.find(f);\r\n    if (i != m.end())\r\n    {\r\n      \/\/ VS2010 says:\r\n      \/\/ error C2440: 'initializing' : \r\n      \/\/ cannot convert from 'const FooT' to 'int *'\r\n      s = i->second;\r\n    }\r\n  }\r\n\r\n  return 0;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Another day, another compiler\/library bug. If you&#8217;re unfortunate enough to still be using Visual Studio 2010, don&#8217;t use tuples as map keys. #include #include #include using namespace std; typedef tuple FooT; typedef map MapT; int main(int, char*[]) { MapT m; \/\/ put a value in the map { FooT f(nullptr,&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,8],"tags":[],"class_list":["post-1024","post","type-post","status-publish","format-standard","hentry","category-cpp","category-programming"],"_links":{"self":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1024"}],"version-history":[{"count":4,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1024\/revisions"}],"predecessor-version":[{"id":1030,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1024\/revisions\/1030"}],"wp:attachment":[{"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.elbeno.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}