summaryrefslogtreecommitdiffstats
path: root/base/move.h
diff options
context:
space:
mode:
authorseanparent@google.com <seanparent@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-19 21:59:01 +0000
committerseanparent@google.com <seanparent@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-19 21:59:01 +0000
commit0fecda62ce784048c032bbe31c7aeaeb8d5cdeab (patch)
tree304f230ebe78ffbcea1a217fa4fd88f23b854bc3 /base/move.h
parent5fde9812dbd02a294af8eb5966548fae2884bd98 (diff)
downloadchromium_src-0fecda62ce784048c032bbe31c7aeaeb8d5cdeab.zip
chromium_src-0fecda62ce784048c032bbe31c7aeaeb8d5cdeab.tar.gz
chromium_src-0fecda62ce784048c032bbe31c7aeaeb8d5cdeab.tar.bz2
Notification for battery with <= 15 minutes remaining.
BUG=521 TEST=none Review URL: http://codereview.chromium.org/1079007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/move.h')
-rw-r--r--base/move.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/base/move.h b/base/move.h
new file mode 100644
index 0000000..eb66070
--- /dev/null
+++ b/base/move.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2010 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.
+
+#ifndef BASE_MOVE_H_
+#define BASE_MOVE_H_
+
+#include <algorithm>
+
+namespace base {
+
+// The move function provides a functional form of swap to move a swappable
+// value leverage the compiler return value optimization and avoiding copy.
+//
+// The type being moved must have an efficient swap() and be default
+// contructable and copyable.
+//
+// C++0x will contain an std::move() function that makes use of rvalue
+// references to achieve the same result. When std::move() is available, it
+// can replace base::move().
+//
+// For example, the following code will not produce any copies of the string.
+//
+// std::string f() {
+// std::string result("Hello World");
+// return result;
+// }
+//
+// class Class {
+// public:
+// Class(std::string x) // Pass sink argument by value
+// : m_(move(x)); // Move x into m_
+// private:
+// std::string m_;
+// };
+//
+// int main() {
+// Class x(f()); // the result string of f() is allocated as the temp argument
+// // to x() and then swapped into the member m_. No Strings
+// // are copied by this call.
+// ...
+
+template <typename T> // T models Regular
+T move(T& x) { // NOLINT : Non-const ref for standard library conformance
+ using std::swap;
+ T result;
+ swap(x, result);
+ return result;
+}
+
+} // namespace base
+
+#endif // BASE_MOVE_H_
+