views:

17

answers:

1

On compiling code at Warning Level 4 (/W4), I get C4996 warnings on std::copy() calls whose parameters are C arrays (not STL containers like vectors). The recommended solution to fix this seems to be to use stdext::checked_array_iterator.

What is the use of stdext::checked_array_iterator? How does it work?

Why does it not give any compile warning on this piece of erroneous code compiled under Visual C++ 2010?:

#include <algorithm>
#include <iterator>
using namespace std;

int main()
{
    int arr0[5] = {100, 99, 98, 97, 96};
    int arr1[3];
    copy( arr0, arr0 + 5, stdext::checked_array_iterator<int*>( arr1, 3 ) );

    return 0;
}
+1  A: 

This page, Checked Iterators, describe how it works, but this quote sums it up: Checked iterators ensure that you do not overwrite the bounds of your container.

So if you go outside the bounds of the iterator it'll either throw and exception or call invalid_parameter.

ho1

related questions