-
Notifications
You must be signed in to change notification settings - Fork 236
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
[C++/WinRT] Helpers to make it easier to copy data from one collection type (std::initializer_list, etc.) to another (IVector, ValueSet, etc.) #356
Comments
I've tagged a few project maintainers. If one of them is available to offer guidance and mentorship for this issue, they will reach out according to the contributing guide to discuss and agree on an approach. @microsoft/cppwinrt-maintainers For what it's worth, the set of available constructors is defined by the class itself in metadata. It does not seem like something that we can or should infer beyond what's in metadata. |
While we often add convenience methods, those methods typically map 1:1 to an existing API. Examples:
There is no way to construct a ValueSet from an existing iterable of key-value pairs, nor is there a way to bulk-insert items into a If you feel so inclined, you could add a template<typename K, typename V>
struct winrt_map_inserter : public std::iterator< std::output_iterator_tag, void, void, void, void >
{
winrt_map_inserter(IMap<K, V> const& map) : map(map) {}
template<typename U>
winrt_map_inserter& operator=(U const& kvp)
{
map.Insert(get<0>(kvp), get<1>(kvp));
return *this;
}
winrt_map_inserter& operator*() { return *this; }
winrt_map_inserter& operator++() { return *this; }
winrt_map_inserter& operator++(int) { return *this; }
IMap<K, V> map;
}; Then you could write std::copy(list.begin(), list.end(), wil::winrt_map_inserter(valueSet)); to bulk-fill a ValueSet or any other map type. Note that |
I'm currently working on a version of a "make value set" helper that takes an init-list of +1 on the "this should go wil" though. |
For vectors, at least you could add an AppendRange method (similar to C++23's std::vector) that combines GetMany and ReplaceAll. |
There are a few classes, such as ValueSet, in the inbox WinRT API set that implement collection interfaces. Currently populating them requires multiple IVector::Append or IMap::Insert calls, which is inconvenient. Consider adding a std::initializer_list constructor (and maybe others such as taking iterators) for simplified construction.
The text was updated successfully, but these errors were encountered: