locked
Convert std::map to IMap

    Question

  • Hi, a quick question: How to convert std:map to IMap? I can't find any concrete WinRT type that implements IMap...
    Sining Oh Blue Star
    Tuesday, September 27, 2011 9:49 AM

Answers

  • I wrote collection.h. Platform::Map<K, V> implements WFC::IMap<K, V> (actually IObservableMap) and is directly constructible from std::map<K, V> (both copy and move).

    • Proposed as answer by SimonRev Wednesday, September 28, 2011 9:09 PM
    • Marked as answer by SALX Friday, September 30, 2011 5:29 AM
    Wednesday, September 28, 2011 7:24 PM
  • You might want to look at Platform::Map.

    Raman

    • Marked as answer by SALX Wednesday, September 28, 2011 2:22 AM
    Tuesday, September 27, 2011 2:37 PM

All replies

  • You might want to look at Platform::Map.

    Raman

    • Marked as answer by SALX Wednesday, September 28, 2011 2:22 AM
    Tuesday, September 27, 2011 2:37 PM
  • Thanks. But I can't find Platform::Map. It doesn't show in intellisence, and even if I manually write it, I get a compile error when I build the application telling me Map is not a member of Platform. IMap is defined under the Windows::Foundation::Collections namespace. But there's no concrete class that implements IMap under the same namespace.
    Sining Oh Blue Star
    Wednesday, September 28, 2011 2:16 AM
  • Oh, forgot to reference collection.h. Once I referened it, I found Platform::Map. Now trying to see how to convert std:map to it. Thanks for the help.
    Sining Oh Blue Star
    Wednesday, September 28, 2011 2:22 AM
  • There is no built-in helper function/class to do this conversion. I was discussing this just yesterday with someone. You'd need to write your own converison code and also keep in mind that you'd need to convert the C++ type into the appropriate RT type (example: map<int, wstring> will become a Map<int, String^>).
    http://blog.voidnish.com
    Wednesday, September 28, 2011 1:31 PM
  • I wrote collection.h. Platform::Map<K, V> implements WFC::IMap<K, V> (actually IObservableMap) and is directly constructible from std::map<K, V> (both copy and move).

    • Proposed as answer by SimonRev Wednesday, September 28, 2011 9:09 PM
    • Marked as answer by SALX Friday, September 30, 2011 5:29 AM
    Wednesday, September 28, 2011 7:24 PM