共用方式為


make_unchecked_array_iterator

建立其他演算法可使用的 unchecked_array_iterator

注意事項注意事項

這個函式是 Standard C++ 程式庫的 Microsoft 擴充功能。透過使用這個函式實作的程式碼不可移植到不支援此 Microsoft 擴充功能的 C++ Standard 建置環境。

template <class Iter>
  unchecked_array_iterator<Iter> 
    make_unchecked_array_iterator(
      Iter Ptr
);

參數

  • Ptr
    目的陣列的指標。

傳回值

unchecked_array_iterator 的執行個體。

備註

make_unchecked_array_iterator 函式是在 stdext 命名空間中定義。

這個函式會使用原始指標,並將它包裝在不執行檢查 (因此最佳化而不執行任何動作) 的類別中,不過,它也會關閉編譯器警告訊息,例如 C4996。 因此,這是處理未檢查指標警告的目標方式,而不需要全域關閉警告訊息或產生檢查成本。 如需詳細資訊與程式碼範例,請參閱已檢查的迭代器

範例

在下列範例中,會建立向量並填入 10 個項目。 向量的內容是透過使用複製演算法複製到陣列,然後 make_unchecked_array_iterator 會用來指定目的。

// make_unchecked_array_iterator.cpp
// compile with: /EHsc /W4 /MTd

#include <algorithm>
#include <iterator> // stdext::make_unchecked_array_iterator
#include <iostream>
#include <vector>
#include <string>

using namespace std;

template <typename C> void print(const string& s, const C& c) {
    cout << s;

    for (const auto& e : c) {
        cout << e << " ";
    }

    cout << endl;
}

int main()
{
    const size_t dest_size = 10;
    int *dest = new int[dest_size];
    vector<int> v;

    for (int i = 0; i < dest_size; ++i) {
        v.push_back(i);
    }
    print("vector v: ", v);

    // COMPILER WARNING SILENCED: stdext::unchecked_array_iterator is marked as checked in debug mode
    // (it performs no checking, so an overrun will trigger undefined behavior)
    copy(v.begin(), v.end(), stdext::make_unchecked_array_iterator(dest));

    cout << "int array dest: ";
    for (int i = 0; i < dest_size; ++i) {
        cout << dest[i] << " ";
    }
    cout << endl;

    delete[] dest;
}

Output

vector v: 0 1 2 3 4 5 6 7 8 9
int array dest: 0 1 2 3 4 5 6 7 8 9

需求

標頭:<iterator>

**命名空間:**stdext

請參閱

參考

標準樣板程式庫