Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: base/bind_unittest.cc

Issue 1653023003: Specialize IsMoveOnlyType<T> for vectors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/callback_internal.h » ('j') | base/callback_internal.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind_unittest.cc
diff --git a/base/bind_unittest.cc b/base/bind_unittest.cc
index fe72f281e75bce8f5d9a908e5cff9bd5a993a41e..3078cd5ae8be81a83366fb3d09c139263ceb4980 100644
--- a/base/bind_unittest.cc
+++ b/base/bind_unittest.cc
@@ -6,6 +6,7 @@
#include <memory>
#include <utility>
+#include <vector>
#include "base/callback.h"
#include "base/macros.h"
@@ -784,6 +785,37 @@ TYPED_TEST(BindMoveOnlyTypeTest, UnboundForwarding) {
EXPECT_EQ(1, deletes);
}
+void VerifyVector(const vector<scoped_ptr<int>>& v) {
+ ASSERT_EQ(1u, v.size());
+ EXPECT_EQ(12345, *v[0]);
+}
+
+std::vector<scoped_ptr<int>> AcceptAndReturnMoveOnlyVector(
+ vector<scoped_ptr<int>> v) {
+ VerifyVector(v);
+ return v;
+}
+
+// Test that a vector containing move-only types can be used with Callback.
+TEST_F(BindTest, BindMoveOnlyVector) {
+ using MoveOnlyVector = std::vector<scoped_ptr<int>>;
+
+ MoveOnlyVector v;
+ v.push_back(make_scoped_ptr(new int(12345)));
+
+ // Early binding should work:
+ base::Callback<MoveOnlyVector()> bound_cb =
+ base::Bind(&AcceptAndReturnMoveOnlyVector, Passed(&v));
+ MoveOnlyVector intermediate_result = bound_cb.Run();
+ VerifyVector(intermediate_result);
+
+ // As should passing it as an argument to Run():
+ base::Callback<MoveOnlyVector(MoveOnlyVector)> unbound_cb =
+ base::Bind(&AcceptAndReturnMoveOnlyVector);
+ MoveOnlyVector final_result = unbound_cb.Run(std::move(intermediate_result));
+ VerifyVector(final_result);
+}
+
// Argument Copy-constructor usage for non-reference parameters.
// - Bound arguments are only copied once.
// - Forwarded arguments are only copied once.
« no previous file with comments | « no previous file | base/callback_internal.h » ('j') | base/callback_internal.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698