locked
WinRT collections not support WinRT value types ?

    Question

  • I tried to compile some code using the Map/MapView in collections.h, I was using some WinRT enum class / value struct as the value type, but these wont compile.

    Is this supported or not ?




    • Edited by TheCat666 Sunday, September 18, 2011 5:47 PM
    Sunday, September 18, 2011 4:49 PM

Answers

  • Hi, I'm the author of collection.h.  The problem with value structs and enum classes is being tracked by an active compiler bug.  collection.h is powered by the STL, and when such types are given to the STL, the compiler introduces % symbols, which the STL can't deal with.

    (Additionally, for Map/MapView, you need to provide a comparator.  It defaults to std::less<K>.)

    • Marked as answer by TheCat666 Tuesday, September 20, 2011 4:35 AM
    Monday, September 19, 2011 9:07 PM

All replies

  • If you don't show your code, we can't possibly know what you did wrong.
    Sunday, September 18, 2011 4:55 PM
  • OK I rechecked my problem, apparently, its 'value struct' or 'enum class' that can't be used in the type arguments of Map.

    for example, if you have these

    	public value struct SomeStruct { };
    	public enum class SomeEnum { Foo, Bar };
    

     

    then any of these wont compile

     

    	auto map1 = ref new Platform::Map<SomeEnum, int>();
    	auto map2 = ref new Platform::Map<int, SomeValue>();
    


     

     



    • Edited by TheCat666 Sunday, September 18, 2011 5:30 PM
    Sunday, September 18, 2011 5:28 PM
  • Hmmm... can't use value struct in std::map either.
    Sunday, September 18, 2011 6:04 PM
  • Even Vector does not seem to work.

     

     

    public value struct SomeStruct { };
    
    Platform::Vector<SomeStruct> vec0; // <-- won't compile

     

    A preview-release bug I guess.


    http://blog.voidnish.com


    Monday, September 19, 2011 4:18 PM
  • The following compiles though:

    Platform::Vector<SomeStruct>^ vec0;

    So I assume the bug is in the simulate-stack-semantics part of the compiler.


    http://blog.voidnish.com
    Monday, September 19, 2011 4:21 PM
  • Vector is OK, but Map is not working.
    Monday, September 19, 2011 5:00 PM
  • Vector is OK for normal syntax, but it won't compile if you use the syntax-sugar for stack semantics. (works fine for built in value types like int).
    http://blog.voidnish.com
    Monday, September 19, 2011 5:12 PM
  • Hi, I'm the author of collection.h.  The problem with value structs and enum classes is being tracked by an active compiler bug.  collection.h is powered by the STL, and when such types are given to the STL, the compiler introduces % symbols, which the STL can't deal with.

    (Additionally, for Map/MapView, you need to provide a comparator.  It defaults to std::less<K>.)

    • Marked as answer by TheCat666 Tuesday, September 20, 2011 4:35 AM
    Monday, September 19, 2011 9:07 PM