locked
Quickest way to convert Platform::Collections::Vector to a std::vector

    Question

  • I have a Platform::Vector that is bound to by the front end and it's working great. I need to use the remove_if on that vector, I did with the begin and end helpers but now I need to use the erase function that is directly off of the std::vector object. Therefore I need to convert my Platform::Vector to a std::vector. What is the quickest way to do that? std::copy and std::copy_if fail and a static_cast fails.

    Thanks,

    Bubba

    Friday, June 28, 2013 1:13 PM

Answers

  • The other way around. I need to convert a IVector or Vector to a std::vector, but thanks anyway.

    edit:

    Apparently there is no quick way to do this.

    • Edited by BubbaRichard Saturday, July 06, 2013 3:58 PM Simple edit
    • Marked as answer by BubbaRichard Saturday, July 06, 2013 3:58 PM
    Friday, June 28, 2013 2:04 PM
  • //declare and filled elsewhere
    Windows::Foundation::Collections::IVector<Entry^>^ _oldVect 
    
    //to copy
    std::vector<Entry^> selectedEnts(_oldVect->Entries->Size);
    std::copy(begin(_oldVect->Entries), end(_oldVect->Entries), selectedEnts.begin());

    This was my final solution, it works, coping the complex class from a IVector vector to a std::vector
    • Marked as answer by BubbaRichard Wednesday, July 17, 2013 11:04 PM
    Wednesday, July 17, 2013 11:04 PM

All replies

  • You may try something like

        std::vector<int> stdVec;
        
        stdVec.push_back(10);
        stdVec.push_back(20);
        stdVec.push_back(30);
       
        // Implicit conversion to IVector
        IVector<int>^ pVect = ref new Vector<int>(std::move(stdVec));

    Friday, June 28, 2013 1:59 PM
  • The other way around. I need to convert a IVector or Vector to a std::vector, but thanks anyway.

    edit:

    Apparently there is no quick way to do this.

    • Edited by BubbaRichard Saturday, July 06, 2013 3:58 PM Simple edit
    • Marked as answer by BubbaRichard Saturday, July 06, 2013 3:58 PM
    Friday, June 28, 2013 2:04 PM
  • // Existing vector:
    Vector<int>^ old_vector = ref new Vector<int>();
    
    // New vector (make a copy):
    std::vector<int> new_vector;
    for(int vector_val : old_vector)
       new_vector.push_back(vector_val);
    Could this be something you are looking for?
    Wednesday, July 17, 2013 9:38 PM
  • //declare and filled elsewhere
    Windows::Foundation::Collections::IVector<Entry^>^ _oldVect 
    
    //to copy
    std::vector<Entry^> selectedEnts(_oldVect->Entries->Size);
    std::copy(begin(_oldVect->Entries), end(_oldVect->Entries), selectedEnts.begin());

    This was my final solution, it works, coping the complex class from a IVector vector to a std::vector
    • Marked as answer by BubbaRichard Wednesday, July 17, 2013 11:04 PM
    Wednesday, July 17, 2013 11:04 PM
  • I know this thread is pretty old but since it's among the first results in google, here are my $0.02.

    The template function Windows::Foundation::Collections::to_vector would take an IVector and convert it to std::vector.

    Wednesday, April 22, 2015 11:39 PM