forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This was brought up in the discussion of https://crrev.com/c/1611240 that we should make it moveable to avoid heap allocations when we have to pass it around. TBR=oshima@chromium.org BUG=866622 TEST=base_unittests, and existing ash_unittests. Change-Id: I7c6fb3c010c01129e6dcc8a0155bb53d35d295d4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1613371 Reviewed-by: Ahmed Fakhry <afakhry@chromium.org> Reviewed-by: Mitsuru Oshima <oshima@chromium.org> Reviewed-by: kylechar <kylechar@chromium.org> Commit-Queue: Ahmed Fakhry <afakhry@chromium.org> Cr-Commit-Position: refs/heads/master@{#660112}
- Loading branch information
Ahmed Fakhry
authored and
Commit Bot
committed
May 15, 2019
1 parent
df499b7
commit 3571b4f
Showing
5 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/auto_reset.h" | ||
|
||
#include <utility> | ||
|
||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
namespace base { | ||
|
||
TEST(AutoReset, Move) { | ||
int value = 10; | ||
{ | ||
AutoReset<int> resetter1{&value, 20}; | ||
EXPECT_EQ(20, value); | ||
{ | ||
value = 15; | ||
AutoReset<int> resetter2 = std::move(resetter1); | ||
// Moving to a new resetter does not change the value; | ||
EXPECT_EQ(15, value); | ||
} | ||
// Moved-to `resetter2` is out of scoped, and resets to the original value | ||
// that was in moved-from `resetter1`. | ||
EXPECT_EQ(10, value); | ||
value = 105; | ||
} | ||
// Moved-from `resetter1` does not reset to anything. | ||
EXPECT_EQ(105, value); | ||
} | ||
|
||
} // namespace base |