Skip to content

Commit

Permalink
Use std::make_reverse_iterator in password_manager
Browse files Browse the repository at this point in the history
This CL adds the first use of std::make_reverse_iterator, inside the
password_manager component at a place where it shortens an awkwardly
long for-loop header.

It also adds std::make_reverse_iterator to the allowed C++14 features.

Bug: 845426
Change-Id: Ief6983c167b3c85a7d52a25555e8157d4d0f0a1c
Reviewed-on: https://chromium-review.googlesource.com/1078758
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Vaclav Brozek <vabr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562987}
  • Loading branch information
Vaclav Brozek authored and Commit Bot committed May 30, 2018
1 parent 9c029de commit 0860872
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ const FormFieldData* FindUsernameFieldBaseHeuristics(
const FormFieldData* focusable_username = nullptr;
const FormFieldData* username = nullptr;
// Do reverse search to find the closest candidates preceding the password.
for (auto it = std::reverse_iterator<
std::vector<const FormFieldData*>::const_iterator>(
first_relevant_password_it);
for (auto it = std::make_reverse_iterator(first_relevant_password_it);
it != fields.rend(); ++it) {
if ((*it)->form_control_type == "password")
continue;
Expand Down
8 changes: 8 additions & 0 deletions styleguide/c++/c++11.html
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,14 @@ <h2 id="whitelist"><a name="library-whitelist-14"></a>C++14 Allowed Library Feat
<td></td>
</tr>

<tr>
<td>Reverse Iterator Adaptor</td>
<td><code>std::make_reverse_iterator()</code></td>
<td>For a given iterator, deduces the type of a corresponding reverse iterator and constructs it.</td>
<td><a href="http://en.cppreference.com/w/cpp/iterator/make_reverse_iterator">std::make_reverse_iterator</a></td>
<td>Useful to reduce boilerplate when constructing reverse iterators. The alternative is using <code>std::reverse_iterator<T>(i)</code> where <code>T</code> is the, usually long, type of the iterator <code>i</code>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/qOE1XA0b6Dk">Discussion thread</a></td>
</tr>

</tbody>
</table>

Expand Down

0 comments on commit 0860872

Please sign in to comment.