You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cpp/containers-modern-cpp.md
+14-72Lines changed: 14 additions & 72 deletions
Original file line number
Diff line number
Diff line change
@@ -31,92 +31,34 @@ translation.priority.mt:
31
31
- "pt-br"
32
32
- "tr-tr"
33
33
---
34
-
# Containers (Modern C++)
35
-
By default, use [vector](../standard-library/vector-class.md) as the default sequential container in C++. This is the equivalent of List\<T> in other languages.
34
+
# Containers (Modern C++)
36
35
37
-
```cpp
38
-
vector<string> v;
39
-
v.push_back( "Geddy Lee" );
36
+
By default, use [vector](../standard-library/vector-class.md) as the preferred sequential container in C++. This is equivalent to `List\<T>` in .NET languages.
40
37
38
+
```cpp
39
+
vector<string> apples;
40
+
apples.push_back("Granny Smith");
41
41
```
42
42
43
-
Use [map](../standard-library/map-class.md) (not unordered_map) as the default associative container. Use [set](../standard-library/set-class.md), [multimap](../standard-library/multimap-class.md), [multiset](../standard-library/multiset-class.md) for degenerate & multi cases.
43
+
Use [map](../standard-library/map-class.md) (not `unordered_map`) as the default associative container. Use [set](../standard-library/set-class.md), [multimap](../standard-library/multimap-class.md), and[multiset](../standard-library/multiset-class.md) for degenerate & multi cases.
44
44
45
45
```cpp
46
-
map<string, string> phone_book;
46
+
map<string, string> apple_color;
47
47
// ...
48
-
phone_book["Alex Lifeson"] = "+1 (416) 555-1212";
49
-
48
+
apple_color["Granny Smith"] = "Green";
50
49
```
51
50
52
-
When performance optimization is needed, consider using:
53
-
54
-
1. the array type when embedding is important - for example, as a class member.
55
-
56
-
2. unordered associative containers (unordered_map, et al.): Lower per-element overhead (major) and constant-time lookup (potentially major, sometimes minor). Harder to use correctly and efficiently, because of inconveniences and sharp edges.
When performance optimization is needed, consider using:
59
52
60
-
Don’t use C arrays. (For older APIs, use `f( vec.data(), vec.size() );` .)
53
+
1. The [array](../standard-library/array-class-stl.md) type when embedding is important, for example, as a class member.
61
54
62
-
For another article about containers, see [C++ Standard Library Containers](../standard-library/stl-containers.md).
55
+
2. Unordered associative containers such as [unordered_map]((../standard-library/unordered-map-class.md). These have lower per-element overhead and constant-time lookup, but they can be harder to use correctly and efficiently.
63
56
64
-
## Container Sizes
65
-
The following tables show the container sizes, in bytes, for x86 and x64 platforms. (For these purposes, 32-bit ARM is equivalent to x86.) These tables cover release mode, because debug mode contains checking machinery that consumes space and time. The separate columns are for [!INCLUDE[cpp_orcas_long](../cpp/includes/cpp_orcas_long_md.md)] SP1, where `_SECURE_SCL` defaulted to 1, and for [!INCLUDE[cpp_orcas_long](../cpp/includes/cpp_orcas_long_md.md)] SP1 with `_SECURE_SCL` manually set to 0 for maximum speed. Visual C++ in Visual Studio 2010, [!INCLUDE[cpp_dev11_long](../build/includes/cpp_dev11_long_md.md)], and [!INCLUDE[cpp_dev12_long](../build/reference/includes/cpp_dev12_long_md.md)] default `_SECURE_SCL` to 0 (now known as `_ITERATOR_DEBUG_LEVEL`).
57
+
3. Sorted `vector`. For more information, see [Algorithms](../cpp/algorithms-modern-cpp.md).
Copy file name to clipboardExpand all lines: docs/security/security-best-practices-for-cpp.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -71,7 +71,7 @@ This article contains information about security tools and practices. Using them
71
71
Each `SafeInt` function protects one mathematical operation from an exploitable error. You can use two different kinds of parameters without converting them to the same type. To protect multiple mathematical operations, use the `SafeInt` class.
72
72
73
73
## Checked Iterators
74
-
A checked iterator enforces container boundaries. By default, when a checked iterator is out of bounds, it generates an exception and ends program execution. A checked iterator provides other levels of response that depend on values that are assigned to preprocessor defines such as **_SECURE_SCL_THROWS** and **_ITERATOR_DEBUG_LEVEL**. For example, at **_ITERATOR_DEBUG_LEVEL=2**, a checked iterator provides comprehensive correctness checks in debug mode, which are made available by using asserts. For more information, see [Checked Iterators](../standard-library/checked-iterators.md).
74
+
A checked iterator enforces container boundaries. By default, when a checked iterator is out of bounds, it generates an exception and ends program execution. A checked iterator provides other levels of response that depend on values that are assigned to preprocessor defines such as **\_SECURE\_SCL\_THROWS** and **\_ITERATOR\_DEBUG\_LEVEL**. For example, at **\_ITERATOR\_DEBUG\_LEVEL=2**, a checked iterator provides comprehensive correctness checks in debug mode, which are made available by using asserts. For more information, see [Checked Iterators](../standard-library/checked-iterators.md) and [\_ITERATOR\_DEBUG\_LEVEL](../standard-library/iterator-debug-level.md).
75
75
76
76
## Code Analysis for Managed Code
77
77
Code Analysis for Managed Code, also known as FxCop, checks assemblies for conformance to the.NET Framework design guidelines. FxCop analyzes the code and metadata in each assembly to check for defects in the following areas:
The reference returned may be invalidated by string reallocations or modifications for the non- **const** strings.
3346
3344
3347
-
When compiling with _SECURE_SCL 1, a runtime error will occur if you attempt to access an element outside the bounds of the string. See [Checked Iterators](../standard-library/checked-iterators.md) for more information.
3345
+
When compiling with [\_ITERATOR\_DEBUG\_LEVEL](../standard-library/iterator-debug-level.md) set to 1 or 2, a runtime error will occur if you attempt to access an element outside the bounds of the string. For more information, see [Checked Iterators](../standard-library/checked-iterators.md).
0 commit comments