Skip to content

Commit f5cd9fb

Browse files
author
Colin Robertson
authored
Merge pull request #2089 from MicrosoftDocs/FromPublicMasterBranch
Confirm merge from FromPublicMasterBranch to master to sync with https://github.com/MicrosoftDocs/cpp-docs (branch master)
2 parents b6c0e1b + 40ab452 commit f5cd9fb

File tree

2 files changed

+79
-9
lines changed

2 files changed

+79
-9
lines changed

docs/mfc/optimizing-control-drawing.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@ Finally, to eliminate unnecessary `SelectObject` calls, modify `OnDraw` as follo
4040
[MFC ActiveX Controls: Optimization](../mfc/mfc-activex-controls-optimization.md)<br/>
4141
[COleControl Class](../mfc/reference/colecontrol-class.md)<br/>
4242
[MFC ActiveX Controls](../mfc/mfc-activex-controls.md)<br/>
43-
[MFC ActiveX Controls](../mfc/mfc-activex-controls.md)<br/>
4443
[MFC ActiveX Control Wizard](../mfc/reference/mfc-activex-control-wizard.md)<br/>
4544
[MFC ActiveX Controls: Painting an ActiveX Control](../mfc/mfc-activex-controls-painting-an-activex-control.md)

docs/standard-library/algorithm-functions.md

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,21 @@ int main()
115115
cout << "There are not two adjacent elements that are equal."
116116
<< endl;
117117
else
118-
cout << "There are two adjacent elements that are equal."
119-
<< "\n They have a value of "
120-
<< *( result1 ) << "." << endl;
118+
cout << "There are two adjacent elements that are equal.\n"
119+
<< "They have a value of "
120+
<< *( result1 ) << "." << endl;
121121

122122
result2 = adjacent_find( L.begin( ), L.end( ), twice );
123123
if ( result2 == L.end( ) )
124124
cout << "There are not two adjacent elements where the "
125-
<< " second is twice the first." << endl;
125+
<< "second is twice the first." << endl;
126126
else
127+
{
127128
cout << "There are two adjacent elements where "
128-
<< "the second is twice the first."
129-
<< "\n They have values of " << *(result2++);
130-
cout << " & " << *result2 << "." << endl;
129+
<< "the second is twice the first.\n"
130+
<< "They have values of " << *(result2++)
131+
<< " & " << *result2 << "." << endl;
132+
}
131133
}
132134
```
133135

@@ -164,12 +166,47 @@ A condition to test for. This is a user-defined predicate function object that d
164166

165167
### Return Value
166168

167-
Returns **true** if the condition is detected at each element in the indicated range, and **false** if the condition is not detected at least one time.
169+
Returns **true** if the condition is detected at each element in the indicated range or if the range is empty, and **false** otherwise.
168170

169171
### Remarks
170172

171173
The template function returns **true** only if, for each `N` in the range `[0,Last - first)`, the predicate `comp(*(_First + N))` is **true**.
172174

175+
### Example
176+
177+
```cpp
178+
// alg_all_of.cpp
179+
// compile with: /EHsc
180+
#include <list>
181+
#include <algorithm>
182+
#include <iostream>
183+
184+
int main()
185+
{
186+
using namespace std;
187+
188+
list<int> li { 50, 40, 10, 20, 20 };
189+
list<int>::iterator iter;
190+
191+
cout << "li = ( ";
192+
for (iter = li.begin(); iter != li.end(); iter++)
193+
cout << *iter << " ";
194+
cout << ")" << endl;
195+
196+
// Check if all elements in li are even.
197+
auto is_even = [](int elem){ return !(elem % 2); };
198+
if (all_of(li.begin(), li.end(), is_even))
199+
cout << "All the elements are even numbers.\n";
200+
else
201+
cout << "Not all the elements are even numbers.\n";
202+
}
203+
```
204+
205+
```Output
206+
L = ( 50 40 10 20 20 )
207+
All the elements are even numbers.
208+
```
209+
173210
## <a name="any_of"></a> any_of
174211

175212
Returns **true** when a condition is present at least once in the specified range of elements.
@@ -203,6 +240,40 @@ The template function returns **true** only if, for some `N` in the range
203240

204241
`[0, last - first)`, the predicate `comp(*(first + N))` is true.
205242

243+
### Example
244+
245+
```cpp
246+
// alg_any_of.cpp
247+
// compile with: /EHsc
248+
#include <list>
249+
#include <algorithm>
250+
#include <iostream>
251+
252+
int main()
253+
{
254+
using namespace std;
255+
256+
list<int> li { 51, 41, 11, 21, 20 };
257+
258+
cout << "li = ( ";
259+
for (auto const& el : li)
260+
cout << el << " ";
261+
cout << ")" << endl;
262+
263+
// Check if there is an even elememt in li.
264+
auto is_even = [](int const elem){ return !(elem % 2); };
265+
if (any_of(li.begin(), li.end(), is_even))
266+
cout << "There's an even element in li.\n";
267+
else
268+
cout << "There are no even elements in li.\n";
269+
}
270+
```
271+
272+
```Output
273+
L = ( 51 41 11 21 20 )
274+
There's an even element in li.
275+
```
276+
206277
## <a name="binary_search"></a> binary_search
207278

208279
Tests whether there is an element in a sorted range that is equal to a specified value or that is equivalent to it in a sense specified by a binary predicate.

0 commit comments

Comments
 (0)