none
[UWP][C++/WinRT] End iterator of IVector RRS feed

  • Question

  • IVector has a method First (inherited from IIterable), but there is no other method to access end iterator and operator "+" for iterator isn't overloaded, so vector.First() + vector.size() gives following error:

    Error    C2678     binary '+': no operator found which takes a left-hand operand of type 'winrt::Windows::Foundation::Collections::IIterator<T>' (or there is no acceptable conversion)
        with
        [
            T=winrt::Windows::Foundation::IInspectable
        ] 

    C++/CX has a begin and end functions which made possible to use Collections types with C++ Standard Library, like for example, sort function.

    In another words: how can I sort a Collection in C++/WinRT without writing my own sorting function?


    • Edited by Jude Allen Monday, July 1, 2019 2:16 PM
    Monday, July 1, 2019 2:14 PM

All replies

  • Hi,
    In my research,It seems we can't directly sort the IVector in winrt.But you can try to sort the std::vector collection and then convert it to the IVector.
    std::vector<int> myV{ 1,3,5,2 };
    
     std::sort(myV.begin(),myV.end());​
     for (int singleV : myV) {​
      int num = singleV;​
     }​
     IVector<int> myColl = winrt::single_threaded_vector<int>(std::move(myV));

    Best regards,
    Fay
    Tuesday, July 2, 2019 3:26 AM
  • Hi,

    Does @Fay's reply make sense?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 12, 2019 6:17 AM
    Moderator