Interest in a checked array iterator?

Hi all, In a similar style to the 'small array count' utility that is being discussed on another thread, would people be interested in an array iterator that is bounds checked in debug builds? Similar to the STLPort debug iterators. In release builds the iterator is pointer type, and incurs no overhead. Its advantage over using boost::array is that that you don't need to specify the size of the array. It also makes using arrays with STL easier by providing begin() and end(), which I find can be error prone and unwieldy for arrays. So rather than : std::sort(&array[0], &array[size(array)]); we have : std::sort(begin(array), end(array)); Usage is shown below. Sam ---------- using namespace array; int notconst[8] = { 8, 7, 6, 5, 4, 3, 2, 1 }; const int const_[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; const int bigarray[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,}; std::cout << "bigarray[] has " << size(bigarray) << " ints in it.\n"; std::copy(begin(const_), end(const_), begin(notconst)); iterator<int>::type it(std::find(begin(notconst), end(notconst), 7)); if (it != end(notconst)) { *it = 8; } // this will assert on the last element output // - there are 9 elements being written into a 8 element array std::copy(begin(bigarray), end(bigarray), begin(notconst));
participants (1)
-
Sam Partington