Collections (Visual C++ for Windows Runtime)

Expand
2 out of 3 rated this helpful - Rate this topic

Collections (Visual C++ for Windows Runtime)

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

The Windows Runtime defines several collection types that you use when you pass collections across the ABI boundary. In many cases there exists an implicit conversion between the Windows Runtime types and the standard C++ types. This means that you can use types like std::vector and std::map internally, and then convert them to the equivalent Windows Runtime type when necessary. You can also operate on Windows Runtime collections by using the iterators and algorithms defined in the C++ standard library.

#include <vector>
#include <algorithm>
#include <collection.h>
using namespace Windows::Foundation::Collections;
IVectorView<int>^ Producer()
{
  std::vector<int> v;
  v.push_back(1);
  v.push_back(2);
  return ref new Platform::VectorView<int>(v);
}
int sum = 0;
IVectorView<int> ^v = Producer();
std::for_each(begin(v), end(v), [&sum](int i) { sum += i; });

Did you find this helpful?
(1500 characters remaining)