make_checked_array_iterator
알고리즘에서 사용할 수 있는 checked_array_iterator를 만듭니다.
참고
이 함수는 표준 C++ 라이브러리의 Microsoft 확장입니다.이 함수를 사용하여 구현한 코드는 이 Microsoft 확장을 지원하지 않는 C++ 표준 빌드 환경으로 이식할 수 없습니다.
template <class Iter>
checked_array_iterator<Iter>
make_checked_array_iterator(
Iter Ptr,
size_t Size,
size_t Index = 0
);
매개 변수
Ptr
대상 배열에 대한 포인터입니다.Size
대상 배열의 크기입니다.Index
배열에 대한 선택적 크기입니다.
반환 값
checked_array_iterator의 인스턴스입니다.
설명
make_checked_array_iterator 함수는 stdext 네임스페이스에 정의되어 있습니다.
이 함수는 원시 포인터를 사용하며, 경계를 벗어나 확인하지 않는 checked_array_iterator 클래스로 래핑되는 경우가 일반적입니다. 해당 클래스는 확인된 것으로 표시되고 STL은 그에 대해 경고하지 않습니다. 자세한 내용 및 코드 예제를 보려면 Checked Iterators를 참조하십시오.
예제
다음 예제에서는 벡터를 만들고 10개 항목으로 채웁니다. 벡터 콘텐츠는 복사 알고리즘을 사용하여 배열로 복사된 다음, make_checked_array_iterator를 사용하여 대상을 지정합니다. 그러면 디버그 어설션 실패를 트리거할 수 있도록 고의적 경계 위반 확인을 수행합니다.
// make_checked_array_iterator.cpp
// compile with: /EHsc /W4 /MTd
#include <algorithm>
#include <iterator> // stdext::make_checked_array_iterator
#include <memory> // std::make_unique
#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;
// Old-school but not exception safe, favor make_unique<int[]>
// int* dest = new int[dest_size];
unique_ptr<int[]> updest = make_unique<int[]>(dest_size);
int* dest = updest.get(); // get a raw pointer for the demo
vector<int> v;
for (int i = 0; i < dest_size; ++i) {
v.push_back(i);
}
print("vector v: ", v);
copy(v.begin(), v.end(), stdext::make_checked_array_iterator(dest, dest_size));
cout << "int array dest: ";
for (int i = 0; i < dest_size; ++i) {
cout << dest[i] << " ";
}
cout << endl;
// Add another element to the vector to force an overrun.
v.push_back(10);
// The next line causes a debug assertion when it executes.
copy(v.begin(), v.end(), stdext::make_checked_array_iterator(dest, dest_size));
}
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