Commit a234a077 authored by pkasting's avatar pkasting Committed by Commit bot

Allow use of container cbegin() and cend() methods, plus sample uses.

This also fixes a small bug in the histogram recording of TabStripModelStatsRecorder::ActiveTabChanged() I spotted while doing this.

BUG=none
TEST=none

Review URL: https://codereview.chromium.org/1675483002

Cr-Commit-Position: refs/heads/master@{#374827}
parent 0cb852e8
......@@ -168,14 +168,14 @@ void TabStripModelStatsRecorder::ActiveTabChanged(
// A UMA Histogram must be bounded by some number.
// We chose 64 as our bound as 99.5% of the users open <64 tabs.
const int kMaxTabHistory = 64;
auto it = std::find(active_tab_history_.begin(), active_tab_history_.end(),
auto it = std::find(active_tab_history_.cbegin(), active_tab_history_.cend(),
new_contents);
int age = it != active_tab_history_.end() ? (it - active_tab_history_.begin())
: (kMaxTabHistory - 1);
int age = (it != active_tab_history_.cend()) ?
(it - active_tab_history_.cbegin()) : (kMaxTabHistory - 1);
if (was_inactive) {
UMA_HISTOGRAM_ENUMERATION(
"Tabs.StateTransfer.NumberOfOtherTabsActivatedBeforeMadeActive",
std::min(age, kMaxTabHistory), kMaxTabHistory);
std::min(age, kMaxTabHistory - 1), kMaxTabHistory);
}
active_tab_history_.insert(active_tab_history_.begin(), new_contents);
......
......@@ -588,11 +588,10 @@ void BrowserActionsContainer::WriteDragDataForView(View* sender,
toolbar_actions_bar_->OnDragStarted();
DCHECK(data);
ToolbarActionViews::iterator iter = std::find(toolbar_action_views_.begin(),
toolbar_action_views_.end(),
sender);
DCHECK(iter != toolbar_action_views_.end());
ToolbarActionViewController* view_controller = (*iter)->view_controller();
auto it = std::find(toolbar_action_views_.cbegin(),
toolbar_action_views_.cend(), sender);
DCHECK(it != toolbar_action_views_.cend());
ToolbarActionViewController* view_controller = (*it)->view_controller();
gfx::Size size(ToolbarActionsBar::IconWidth(false),
ToolbarActionsBar::IconHeight());
drag_utils::SetDragImageOnDataObject(
......@@ -601,7 +600,7 @@ void BrowserActionsContainer::WriteDragDataForView(View* sender,
data);
// Fill in the remaining info.
BrowserActionDragData drag_data(view_controller->GetId(),
iter - toolbar_action_views_.begin());
it - toolbar_action_views_.cbegin());
drag_data.Write(browser_->profile(), data);
}
......
......@@ -357,13 +357,10 @@ Note that &lt;algorithm&gt; contains a range-based <code>move</code> method. Th
<tr>
<td>Begin and End Non-Member Functions</td>
<td><code>std::begin()</code> and <code>std::end()</code></td>
<td>Allows use of free functions on any container, including
fixed-size arrays</td>
<td><a href="http://en.cppreference.com/w/cpp/iterator/begin">
std::begin</a> and
<a href="http://en.cppreference.com/w/cpp/iterator/end">
std::end</a></td>
<td>Useful for fixed-size arrays. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/5iFNE8P5qT4/discussion">Discussion thread</a></td>
<td>Allows use of free functions on any container, including fixed-size arrays</td>
<td><a href="http://en.cppreference.com/w/cpp/iterator/begin">std::begin</a> and <a href="http://en.cppreference.com/w/cpp/iterator/end">std::end</a></td>
<td>Useful for fixed-size arrays. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/5iFNE8P5qT4/discussion">Discussion thread</a><br>
Note that non-member <code>cbegin()</code> and <code>cend()</code> are not available until C++14.</td>
</tr>
<tr>
......@@ -374,6 +371,14 @@ std::end</a></td>
<td>Usage should be rare. <a href='https://groups.google.com/a/chromium.org/forum/#!topic/cxx/vCxo4tZNd_M'>Discussion thread</a></td>
</tr>
<tr>
<td>Constant Iterator Methods on Containers</td>
<td><code>std::vector::cbegin()</code>, <code>std::vector::cend()</code></td>
<td>Allows more widespread use of <code>const_iterator</code></td>
<td>E.g. <a href="http://en.cppreference.com/w/cpp/container/vector/begin">std::vector::cbegin<a> and <a href="http://en.cppreference.com/w/cpp/container/vector/end">std::vector::cend<a></td>
<td>Applies to all containers, not just <code>vector</code>. Consider using <code>const_iterator</code> over <code>iterator</code> where possible for the same reason as using <code>const</code> variables and functions where possible; see Effective Modern C++ item 13 for motivation. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/cS83F_buqLM/discussion">Discussion thread</a></td>
</tr>
<tr>
<td>Containers containing movable types</td>
<td><code>vector&lt;scoped_ptr&gt;</code></td>
......@@ -845,14 +850,6 @@ the <code>&lt;complex&gt;</code> library.</td>
<td></td>
</tr>
<tr>
<td>Constant Iterator Methods on Containers</td>
<td><code>std::vector::cbegin()</code> and <code>std::vector::cend()</code></td>
<td>Enforces iteration methods that don't change container contents</td>
<td><a href="http://en.cppreference.com/w/cpp/container/vector/begin">std::vector::cbegin<a></td>
<td>This applies to all containers, std::vector is just an example. <a href="https://groups.google.com/a/chromium.org/d/topic/cxx/cS83F_buqLM/discussion">Discussion thread</a></td>
</tr>
<tr>
<td>Container Compaction Functions</td>
<td><code>std::vector::shrink_to_fit()</code>,
......
......@@ -3505,12 +3505,8 @@ TEST_F(ViewTest, GetViewByID) {
View::Views views;
v1.GetViewsInGroup(kGroup, &views);
EXPECT_EQ(2U, views.size());
View::Views::const_iterator i(std::find(views.begin(), views.end(), &v3));
EXPECT_NE(views.end(), i);
i = std::find(views.begin(), views.end(), &v4);
EXPECT_NE(views.end(), i);
EXPECT_NE(views.cend(), std::find(views.cbegin(), views.cend(), &v3));
EXPECT_NE(views.cend(), std::find(views.cbegin(), views.cend(), &v4));
}
TEST_F(ViewTest, AddExistingChild) {
......
......@@ -68,11 +68,9 @@ class WMStateWaiter : public X11PropertyChangeWaiter {
bool ShouldKeepOnWaiting(const ui::PlatformEvent& event) override {
std::vector<Atom> hints;
if (ui::GetAtomArrayProperty(xwindow(), "_NET_WM_STATE", &hints)) {
std::vector<Atom>::iterator it = std::find(
hints.begin(),
hints.end(),
auto it = std::find(hints.cbegin(), hints.cend(),
atom_cache_->GetAtom(hint_));
bool hint_set = (it != hints.end());
bool hint_set = (it != hints.cend());
return hint_set != wait_till_set_;
}
return true;
......
......@@ -55,11 +55,9 @@ class MinimizeWaiter : public X11PropertyChangeWaiter {
bool ShouldKeepOnWaiting(const ui::PlatformEvent& event) override {
std::vector<Atom> wm_states;
if (ui::GetAtomArrayProperty(xwindow(), "_NET_WM_STATE", &wm_states)) {
std::vector<Atom>::iterator it = std::find(
wm_states.begin(),
wm_states.end(),
auto it = std::find(wm_states.cbegin(), wm_states.cend(),
atom_cache_->GetAtom("_NET_WM_STATE_HIDDEN"));
return it == wm_states.end();
return it == wm_states.cend();
}
return true;
}
......@@ -97,9 +95,8 @@ class StackingClientListWaiter : public X11PropertyChangeWaiter {
std::vector<XID> stack;
ui::GetXWindowStack(ui::GetX11RootWindow(), &stack);
for (size_t i = 0; i < expected_windows_.size(); ++i) {
std::vector<XID>::iterator it = std::find(
stack.begin(), stack.end(), expected_windows_[i]);
if (it == stack.end())
auto it = std::find(stack.cbegin(), stack.cend(), expected_windows_[i]);
if (it == stack.cend())
return true;
}
return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment