1

Platform::Arrayオブジェクト内のアイテムのシーケンスを別のオブジェクトにコピーしたいPlatform::Array。もちろん、たとえばforループを使用してこれを解決できます。

int srcIdx = srcIdx0;
int destIdx = destIdx0;
for (int i = 0; i < count; ++i, ++srcIdx, ++destIdx)
    dest[destIdx] = src[srcIdx];

私が疑問に思っているのは、C++/CX (コンポーネント拡張) にこの操作をより効率的に実行し、冗長性を減らすための組み込み機能があるかどうかです。

C# にはArray.Copyメソッドがあり、C++/CLI ではMarshal.Copyが少なくとも「プリミティブ」型をコピーするためのオプションになります。

C++ STL にはstd::copyとがありstd::copy_nますが、これらのアルゴリズムはPlatform::Array「反復子」begin()end().

どこかに「隠された」C++/CX の便利なコピー メソッドがありますか、またはforこの操作のために明示的なループにフォールバックする必要がありますか?

4

1 に答える 1

2

現時点では、組み込みのPlatform::Arrayコピー メソッドはないように思われるため、目的のために独自のテンプレート関数を実装しました。

template<typename T> void Copy(
    const Platform::Array<T>^ sourceArray, 
    int sourceIndex, 
    Platform::Array<T>^ destinationArray, 
    int destinationIndex, 
    int length)
{
    for (int i = 0; i < length; ++i, ++sourceIndex, ++destinationIndex)
        destinationArray[destinationIndex] = sourceArray[sourceIndex];
};

コピー部分を改善する方法に関する提案は大歓迎です:-)

于 2013-02-06T10:08:16.110 に答える