{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/cppwinrt/issues/344","repository_url":"https://api.github.com/repos/Microsoft/cppwinrt","labels_url":"https://api.github.com/repos/Microsoft/cppwinrt/issues/344/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/cppwinrt/issues/344/comments","events_url":"https://api.github.com/repos/Microsoft/cppwinrt/issues/344/events","html_url":"https://github.com/Microsoft/cppwinrt/issues/344","id":313466424,"number":344,"title":"How do you store C++\\WinRT types in an STL Collection?","user":{"login":"joejo-unity","id":23105339,"avatar_url":"https://avatars2.githubusercontent.com/u/23105339?v=4","gravatar_id":"","url":"https://api.github.com/users/joejo-unity","html_url":"https://github.com/joejo-unity","followers_url":"https://api.github.com/users/joejo-unity/followers","following_url":"https://api.github.com/users/joejo-unity/following{/other_user}","gists_url":"https://api.github.com/users/joejo-unity/gists{/gist_id}","starred_url":"https://api.github.com/users/joejo-unity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joejo-unity/subscriptions","organizations_url":"https://api.github.com/users/joejo-unity/orgs","repos_url":"https://api.github.com/users/joejo-unity/repos","events_url":"https://api.github.com/users/joejo-unity/events{/privacy}","received_events_url":"https://api.github.com/users/joejo-unity/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-11T19:59:58Z","updated_at":"2018-04-13T16:56:20Z","closed_at":"2018-04-13T16:56:20Z","author_association":"NONE","body":"I need to store instances of C++\\Winrt types in an stl map but am getting the an error obout them not supporting a default constructor. To date I've been getting around this by wrapping them in another type whose sole purpose is to allow me to put it into the map, but that seem a rather untenable plan.\r\n\r\nI tried using an IMap<uint32_t, WinRTType> but the WInRT template wrapper insists on thinking the integer value passed in is an object and tries to access the internal ptr value (which is null if the integer is 0).\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/cppwinrt/issues/comments/381197264","html_url":"https://github.com/Microsoft/cppwinrt/issues/344#issuecomment-381197264","issue_url":"https://api.github.com/repos/Microsoft/cppwinrt/issues/344","id":381197264,"user":{"login":"kennykerr","id":9845234,"avatar_url":"https://avatars1.githubusercontent.com/u/9845234?v=4","gravatar_id":"","url":"https://api.github.com/users/kennykerr","html_url":"https://github.com/kennykerr","followers_url":"https://api.github.com/users/kennykerr/followers","following_url":"https://api.github.com/users/kennykerr/following{/other_user}","gists_url":"https://api.github.com/users/kennykerr/gists{/gist_id}","starred_url":"https://api.github.com/users/kennykerr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kennykerr/subscriptions","organizations_url":"https://api.github.com/users/kennykerr/orgs","repos_url":"https://api.github.com/users/kennykerr/repos","events_url":"https://api.github.com/users/kennykerr/events{/privacy}","received_events_url":"https://api.github.com/users/kennykerr/received_events","type":"User","site_admin":false},"created_at":"2018-04-13T16:56:20Z","updated_at":"2018-04-13T16:56:20Z","author_association":"CONTRIBUTOR","body":"That's not really a C++/WinRT problem and a great question for Stack Overflow. If you have an STL container and want to use types that lack default constructors then you need to use the facilities provided by the container to support such types. For example:\r\n\r\n```C++\r\nusing namespace Windows::Foundation;\r\nusing namespace Windows::Foundation::Collections;\r\n\r\nint main()\r\n{\r\n    init_apartment();\r\n\r\n    Uri key{ L\"http://key.com/\" };\r\n    Uri value{ L\"http://value.com/\" };\r\n\r\n    std::map<Uri, Uri> container;\r\n    container.emplace(std::move(key), std::move(value));\r\n\r\n    for (auto&& pair : container)\r\n    {\r\n        printf(\"%ls %ls\\n\", pair.first.Domain().c_str(), pair.second.Domain().c_str());\r\n    }\r\n}\r\n```"}}
{"actor":{"display_login":"kennykerr"}}