-
Notifications
You must be signed in to change notification settings - Fork 262
Fix ABI conformance of IMap::Remove, add TryRemove #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
|
|
||
| WINRT_EXPORT namespace winrt | ||
| { | ||
| template <typename D, typename T, typename Version = impl::no_collection_version> | ||
|
|
@@ -415,8 +414,14 @@ WINRT_EXPORT namespace winrt | |
|
|
||
| void Remove(K const& key) | ||
| { | ||
| auto& container = static_cast<D&>(*this).get_container(); | ||
| auto found = container.find(static_cast<D const&>(*this).wrap_value(key)); | ||
| if (found == container.end()) | ||
| { | ||
| throw hresult_out_of_bounds(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why it's important that Remove throws when the key is not found, beyond consistency with other implementations?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It prevents
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but it sounds like a circular argument.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TryRemove is needed because if the map came from somebody other than C++/WinRT, it will throw. For example, if you want to "TryRemove" from CoreApplication.Properties, you cannot use "Remove" because that property set is implemented in WRL, not C++/WinRT, and it throws on key not found.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it - thanks. |
||
| } | ||
| this->increment_version(); | ||
| static_cast<D&>(*this).get_container().erase(static_cast<D const&>(*this).wrap_value(key)); | ||
| container.erase(found); | ||
| } | ||
|
|
||
| void Clear() noexcept | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.