【发布时间】:2021-06-27 07:31:57
【问题描述】:
有没有一种方法可以直接对winrt::Windows::Foundation::Collections::IObservableVector<T> 进行排序,而无需创建新向量或将其转换为std::vector<T>?
IObservableVector<int> numbers{ single_threaded_observable_vector<int>() };
numbers.Append(5);
numbers.Append(1);
numbers.Append(3);
std::sort(numbers.begin(), numbers.end());
std::sort 似乎不适用于 C++/WinRT 集合,至少对我来说是这样。
我的进一步目标是在GridView 中显示复杂对象的排序和过滤集合。
如果无法直接排序,将IObservableVector<T> 转换为std::vector<T> 的最有效方法是什么?反之亦然很简单single_threaded_observable_vector<T>(std::move(vec))。
编辑:
根据Raymond Chen's blog,可以使用IVector<T>.GetMany(UInt32, T[]) 将IVector<T> 复制到std::vector<T>。
std::vector<int> vec(numbers.Size());
numbers.GetMany(0, vec);
但是,我仍然不确定在生产应用中复制大型集合的性能。希望有更好的方法。
【问题讨论】:
-
在不创建新向量或将其转换为 std::vector
的情况下,无法直接对 winrt::Windows::Foundation::Collections::IObservableVector 进行排序。
标签: c++ windows uwp windows-runtime c++-winrt