Skip to content

Commit 0230370

Browse files
Merge pull request #5498 from Rageking8/update-checked-iterators-topic
Update "Checked Iterators" topic
2 parents a272254 + e019788 commit 0230370

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

docs/standard-library/checked-iterators.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
11
---
2-
description: "Learn more about: Checked Iterators"
32
title: "Checked Iterators"
4-
ms.date: "11/04/2016"
3+
description: "Learn more about: Checked Iterators"
4+
ms.date: 11/04/2016
55
f1_keywords: ["_SECURE_SCL_THROWS"]
66
helpviewer_keywords: ["Safe Libraries", "Safe Libraries, C++ Standard Library", "Safe C++ Standard Library", "iterators, checked", "checked iterators"]
7-
ms.assetid: cfc87df8-e3d9-403b-ab78-e9483247d940
87
---
98
# Checked Iterators
109

11-
Checked iterators ensure that the bounds of your container are not overwritten. Checked iterators apply to both release builds and debug builds. For more information about how to use debug iterators when you compile in debug mode, see [Debug Iterator Support](../standard-library/debug-iterator-support.md).
10+
Checked iterators ensure that the bounds of your container are not overwritten. Checked iterators apply to both release builds and debug builds. For more information about how to use debug iterators when you compile in debug mode, see [Debug Iterator Support](debug-iterator-support.md).
1211

1312
## Remarks
1413

15-
For information about how to disable warnings that are generated by checked iterators, see [_SCL_SECURE_NO_WARNINGS](../standard-library/scl-secure-no-warnings.md).
14+
For information about how to disable warnings that are generated by checked iterators, see [`_SCL_SECURE_NO_WARNINGS`](scl-secure-no-warnings.md).
1615

17-
You can use the [\_ITERATOR\_DEBUG\_LEVEL](../standard-library/iterator-debug-level.md) preprocessor macro to enable or disable the checked iterators feature. If _ITERATOR_DEBUG_LEVEL is defined as 1 or 2, unsafe use of iterators causes a runtime error and the program is terminated. If defined as 0, checked iterators are disabled. By default, the value for _ITERATOR_DEBUG_LEVEL is 0 for release builds and 2 for debug builds.
16+
You can use the [`_ITERATOR_DEBUG_LEVEL`](iterator-debug-level.md) preprocessor macro to enable or disable the checked iterators feature. If `_ITERATOR_DEBUG_LEVEL` is defined as 1 or 2, unsafe use of iterators causes a runtime error and the program is terminated. If defined as 0, checked iterators are disabled. By default, the value for `_ITERATOR_DEBUG_LEVEL` is 0 for release builds and 2 for debug builds.
1817

1918
> [!IMPORTANT]
20-
> Older documentation and source code may refer to the [_SECURE_SCL](../standard-library/secure-scl.md) macro. Use _ITERATOR_DEBUG_LEVEL to control _SECURE_SCL. For more information, see [_ITERATOR_DEBUG_LEVEL](../standard-library/iterator-debug-level.md).
19+
> Older documentation and source code may refer to the [`_SECURE_SCL`](secure-scl.md) macro. Use `_ITERATOR_DEBUG_LEVEL` to control `_SECURE_SCL`. For more information, see [`_ITERATOR_DEBUG_LEVEL`](iterator-debug-level.md).
2120
22-
When _ITERATOR_DEBUG_LEVEL is defined as 1 or 2, these iterator checks are performed:
21+
When `_ITERATOR_DEBUG_LEVEL` is defined as 1 or 2, these iterator checks are performed:
2322

24-
- All standard iterators (for example, [vector::iterator](../standard-library/vector-class.md#iterator)) are checked.
23+
- All standard iterators (for example, [`vector::iterator`](vector-class.md#iterator)) are checked.
2524

26-
- If an output iterator is a checked iterator, calls to standard library functions such as [std::copy](../standard-library/algorithm-functions.md#copy) get checked behavior.
25+
- If an output iterator is a checked iterator, calls to standard library functions such as [`std::copy`](algorithm-functions.md#copy) get checked behavior.
2726

2827
- If an output iterator is an unchecked iterator, calls to standard library functions cause compiler warnings.
2928

3029
- The following functions generate a runtime error if there is an access that is outside the bounds of the container:
3130

3231
:::row:::
3332
:::column span="":::
34-
  [`basic_string::operator[]`](../standard-library/basic-string-class.md#op_at)\
35-
  [`bitset::operator[]`](../standard-library/bitset-class.md#op_at)\
36-
  [`deque::back`](../standard-library/deque-class.md#back)\
37-
  [`deque::front`](../standard-library/deque-class.md#front)
33+
[`basic_string::operator[]`](basic-string-class.md#op_at)\
34+
[`bitset::operator[]`](bitset-class.md#op_at)\
35+
[`deque::back`](deque-class.md#back)\
36+
[`deque::front`](deque-class.md#front)
3837
:::column-end:::
3938
:::column span="":::
40-
[`deque::operator[]`](../standard-library/deque-class.md#op_at)\
41-
[`list::back`](../standard-library/list-class.md#back)\
42-
[`list::front`](../standard-library/list-class.md#front)\
43-
[`queue::back`](../standard-library/queue-class.md#back)
39+
[`deque::operator[]`](deque-class.md#op_at)\
40+
[`list::back`](list-class.md#back)\
41+
[`list::front`](list-class.md#front)\
42+
[`queue::back`](queue-class.md#back)
4443
:::column-end:::
4544
:::column span="":::
46-
[`queue::front`](../standard-library/queue-class.md#front)\
47-
[`vector::back`](../standard-library/vector-class.md#back)\
48-
[`vector::front`](../standard-library/vector-class.md#front)\
49-
[`vector::operator[]`](../standard-library/vector-class.md#op_at)
45+
[`queue::front`](queue-class.md#front)\
46+
[`vector::back`](vector-class.md#back)\
47+
[`vector::front`](vector-class.md#front)\
48+
[`vector::operator[]`](vector-class.md#op_at)
5049
:::column-end:::
5150
:::row-end:::
5251

53-
When _ITERATOR_DEBUG_LEVEL is defined as 0:
52+
When `_ITERATOR_DEBUG_LEVEL` is defined as 0:
5453

5554
- All standard iterators are unchecked. Iterators can move beyond the container boundaries, which leads to undefined behavior.
5655

@@ -60,11 +59,11 @@ When _ITERATOR_DEBUG_LEVEL is defined as 0:
6059

6160
A checked iterator refers to an iterator that calls `invalid_parameter_handler` if you attempt to move past the boundaries of the container. For more information about `invalid_parameter_handler`, see [Parameter Validation](../c-runtime-library/parameter-validation.md).
6261

63-
The iterator adaptors that support checked iterators are [checked_array_iterator Class](../standard-library/checked-array-iterator-class.md) and [unchecked_array_iterator Class](../standard-library/unchecked-array-iterator-class.md).
62+
The iterator adaptors that support checked iterators are [`checked_array_iterator` Class](checked-array-iterator-class.md) and [`unchecked_array_iterator` Class](unchecked-array-iterator-class.md).
6463

6564
## Examples
6665

67-
When you compile by using _ITERATOR_DEBUG_LEVEL set to 1 or 2, a runtime error will occur if you attempt to access an element that is outside the bounds of the container by using the indexing operator of certain classes.
66+
When you compile by using `_ITERATOR_DEBUG_LEVEL` set to 1 or 2, a runtime error will occur if you attempt to access an element that is outside the bounds of the container by using the indexing operator of certain classes.
6867

6968
```cpp
7069
// checked_iterators_1.cpp
@@ -79,19 +78,19 @@ using namespace std;
7978

8079
int main()
8180
{
82-
vector<int> v;
83-
v.push_back(67);
81+
vector<int> v;
82+
v.push_back(67);
8483

85-
int i = v[0];
86-
cout << i << endl;
84+
int i = v[0];
85+
cout << i << endl;
8786

88-
i = v[1]; //triggers invalid parameter handler
87+
i = v[1]; //triggers invalid parameter handler
8988
}
9089
```
9190

9291
This program prints "67" then pops up an assertion failure dialog box with additional information about the failure.
9392

94-
Similarly, when you compile by using _ITERATOR_DEBUG_LEVEL set to 1 or 2, a runtime error will occur if you attempt to access an element by using `front` or `back` in container classes when the container is empty.
93+
Similarly, when you compile by using `_ITERATOR_DEBUG_LEVEL` set to 1 or 2, a runtime error will occur if you attempt to access an element by using `front` or `back` in container classes when the container is empty.
9594

9695
```cpp
9796
// checked_iterators_2.cpp
@@ -105,15 +104,15 @@ using namespace std;
105104

106105
int main()
107106
{
108-
vector<int> v;
107+
vector<int> v;
109108

110-
int& i = v.front(); // triggers invalid parameter handler
109+
int& i = v.front(); // triggers invalid parameter handler
111110
}
112111
```
113112

114113
This program pops up an assertion failure dialog box with additional information about the failure.
115114

116-
The following code demonstrates various iterator use-case scenarios with comments about each. By default, _ITERATOR_DEBUG_LEVEL is set to 2 in Debug builds, and to 0 in Retail builds.
115+
The following code demonstrates various iterator use-case scenarios with comments about each. By default, `_ITERATOR_DEBUG_LEVEL` is set to 2 in Debug builds, and to 0 in Retail builds.
117116

118117
```cpp
119118
// checked_iterators_3.cpp
@@ -134,7 +133,8 @@ void print(const string& s, const C& c)
134133
{
135134
cout << s;
136135

137-
for (const auto& e : c) {
136+
for (const auto& e : c)
137+
{
138138
cout << e << " ";
139139
}
140140

@@ -219,5 +219,5 @@ a8: 0 8 16 24 32 40 48 56 64 72 80 88 96 104 112 120
219219

220220
## See also
221221

222-
[C++ Standard Library Overview](../standard-library/cpp-standard-library-overview.md)\
223-
[Debug Iterator Support](../standard-library/debug-iterator-support.md)
222+
[C++ Standard Library Overview](cpp-standard-library-overview.md)\
223+
[Debug Iterator Support](debug-iterator-support.md)

0 commit comments

Comments
 (0)