Uwp 移动标准::唯一\u ptr<;int[]>;到平台::集合::向量<;int>;

Uwp 移动标准::唯一\u ptr<;int[]>;到平台::集合::向量<;int>;,uwp,windows-runtime,c++14,move-semantics,c++-cx,Uwp,Windows Runtime,C++14,Move Semantics,C++ Cx,我有一个指向动态数组的std::unique_ptr。如何通过将该数组移动到新的Vector对象中来实例化Platform::Collections::Vector的新实例?理想情况下,类似这样的情况: int length = 1024; std::unique_ptr<int[]> p = std::make_unique<int[]>(length); Vector<int>^ vec = ref new Vector<int>(std::m

我有一个指向动态数组的std::unique_ptr。如何通过将该数组移动到新的Vector对象中来实例化Platform::Collections::Vector的新实例?理想情况下,类似这样的情况:

int length = 1024;
std::unique_ptr<int[]> p = std::make_unique<int[]>(length);
Vector<int>^ vec = ref new Vector<int>(std::move(p), length); // doesn't compile
int length = 1024;
std::unique_ptr<int[]> p = std::make_unique<int[]>(length);
Vector<int>^ vec = ref new Vector<int>(std::vector<int>(std::move(p), length)); // doesn't compile
int-length=1024;
std::unique_ptr p=std::make_unique(长度);
向量^vec=ref新向量(std::move(p),length);//不编译
有一个向量构造函数将std::Vector移动到其中,但是我需要以某种方式将我的唯一的_ptr移动到该std::Vector。我还没有找到这样做的方法,理想情况下应该是这样:

int length = 1024;
std::unique_ptr<int[]> p = std::make_unique<int[]>(length);
Vector<int>^ vec = ref new Vector<int>(std::move(p), length); // doesn't compile
int length = 1024;
std::unique_ptr<int[]> p = std::make_unique<int[]>(length);
Vector<int>^ vec = ref new Vector<int>(std::vector<int>(std::move(p), length)); // doesn't compile
int-length=1024;
std::unique_ptr p=std::make_unique(长度);
向量^vec=ref新向量(std::Vector(std::move(p),length));//不编译
显然,出于性能考虑,我不想复制。有人知道一种正确的方法吗


提前感谢。

您可以将每个值移动到向量元素中(这显然对int没有帮助),但是你不能将分配作为一个整体来移动。我实际上是将它与
double
float
一起使用,所以不幸的是它没有帮助。你想让
unique\u ptr
Vector
指向同一个内存块吗?这是行不通的,因为两者的生命期语义非常不同。。。<代码>向量 >在DLL边界上计数,而 UnQuyJPt只要你在C++代码中保持该对象存活,那么它显然工作在<>代码> STD::向量和矢量< /代码>,因为它有一个构造函数,用R值取<代码> STD::向量< /代码>,因此,我认为它可能也适用于
unique_ptr
。您可以将每个值移动到向量元素中(这显然对int没有帮助),但是你不能将分配作为一个整体来移动。我实际上是将它与
double
float
一起使用,所以不幸的是它没有帮助。你想让
unique\u ptr
Vector
指向同一个内存块吗?这是行不通的,因为两者的生命期语义非常不同。。。<代码>向量 >在DLL边界上计数,而 UnQuyJPt
只要你在C++代码中保持该对象存活,那么它显然工作在<>代码> STD::向量和矢量< /代码>,因为它有一个构造函数,用R值取<代码> STD::向量< /代码>,所以我认为它也可以与
unique\u ptr
一起使用。