I have a object of type of Map<String^, Object^>^
. How do I iterate in C++/CX way? I am trying to use iterator but I am not clear about syntax. Documentation doesn't provide an example.
C++/CX collections follow the same principles as c++ collections, so they have iterators and begin, end functions.
IMap<Platform::String^, Platform::Object^>^ map = ref new Map<Platform::String^, Platform::Object^>();
map->Insert("key1", "val1");
map->Insert("key2", 2.0f);
// Exactly like you would iterate over a map, but instead of std::pair you have IKeyValuePair
std::for_each(begin(map), end(map), [](IKeyValuePair<Platform::String^, Platform::Object^>^ pair)
{
// do stuff
auto key = pair->Key;
auto value = pair->Value;
});
for( auto pair : map )
{
// do stuff
auto key = pair->Key;
auto value = pair->Value;
}
Also, don't forget to include collection.h and use namespace Platform::Collections.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With