Skip to content

Commit

Permalink
Remove base::Tuple
Browse files Browse the repository at this point in the history
base::Tuple has been an alias of std::tuple for the migration. And this
CL completes the migration by:
 - Replace base::Tuple with std::tuple,
 - Replace base::MakeTuple with std::make_tuple,
 - Replace base::get with std::get,
 - Remove base::Tuple, base::MakeTuple, base::get and base::MakeRefTuple

BUG=554987
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2023243002
Cr-Commit-Position: refs/heads/master@{#397652}
  • Loading branch information
tzik authored and Commit bot committed Jun 3, 2016
1 parent c37546a commit 1068f1b
Show file tree
Hide file tree
Showing 49 changed files with 623 additions and 592 deletions.
4 changes: 3 additions & 1 deletion base/bind_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <stddef.h>

#include <tuple>
#include <type_traits>

#include "base/bind_helpers.h"
Expand Down Expand Up @@ -361,7 +362,8 @@ struct Invoker<IndexSequence<bound_indices...>,
// you really want to warp ahead and step through the
// InvokeHelper<>::MakeItSo() call below.
return InvokeHelper<is_weak_call, R>::MakeItSo(
storage->runnable_, Unwrap(get<bound_indices>(storage->bound_args_))...,
storage->runnable_,
Unwrap(std::get<bound_indices>(storage->bound_args_))...,
std::forward<UnboundArgs>(unbound_args)...);
}
};
Expand Down
9 changes: 5 additions & 4 deletions base/observer_list_threadsafe.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <algorithm>
#include <map>
#include <tuple>

#include "base/bind.h"
#include "base/location.h"
Expand Down Expand Up @@ -177,17 +178,17 @@ class ObserverListThreadSafe
void Notify(const tracked_objects::Location& from_here,
Method m,
const Params&... params) {
internal::UnboundMethod<ObserverType, Method, Tuple<Params...>> method(
m, MakeTuple(params...));
internal::UnboundMethod<ObserverType, Method, std::tuple<Params...>> method(
m, std::make_tuple(params...));

AutoLock lock(list_lock_);
for (const auto& entry : observer_lists_) {
ObserverListContext* context = entry.second;
context->task_runner->PostTask(
from_here,
Bind(&ObserverListThreadSafe<ObserverType>::template NotifyWrapper<
Method, Tuple<Params...>>,
this, context, method));
Method, std::tuple<Params...>>,
this, context, method));
}
}

Expand Down
82 changes: 22 additions & 60 deletions base/tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// A Tuple is a generic templatized container, similar in concept to std::pair
// and std::tuple. The convenient MakeTuple() function takes any number of
// arguments and will construct and return the appropriate Tuple object. The
// functions DispatchToMethod and DispatchToFunction take a function pointer or
// instance and method pointer, and unpack a tuple into arguments to the call.
//
// Tuple elements are copied by value, and stored in the tuple. See the unit
// tests for more details of how/when the values are copied.
// Use std::tuple as tuple type. This file contains helper functions for
// working with std::tuples.
// The functions DispatchToMethod and DispatchToFunction take a function pointer
// or instance and method pointer, and unpack a tuple into arguments to the
// call.
//
// Example usage:
// // These two methods of creating a Tuple are identical.
// Tuple<int, const char*> tuple_a(1, "wee");
// Tuple<int, const char*> tuple_b = MakeTuple(1, "wee");
// std::tuple<int, const char*> tuple_a(1, "wee");
// std::tuple<int, const char*> tuple_b = std::make_tuple(1, "wee");
//
// void SomeFunc(int a, const char* b) { }
// DispatchToFunction(&SomeFunc, tuple_a); // SomeFunc(1, "wee")
// DispatchToFunction(
// &SomeFunc, MakeTuple(10, "foo")); // SomeFunc(10, "foo")
// &SomeFunc, std::make_tuple(10, "foo")); // SomeFunc(10, "foo")
//
// struct { void SomeMeth(int a, int b, int c) { } } foo;
// DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3));
// DispatchToMethod(&foo, &Foo::SomeMeth, std::make_tuple(1, 2, 3));
// // foo->SomeMeth(1, 2, 3);

#ifndef BASE_TUPLE_H_
Expand Down Expand Up @@ -110,43 +107,6 @@ struct MakeIndexSequenceImpl<N, Ns...>
template <size_t N>
using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type;

// Tuple -----------------------------------------------------------------------
//
// This set of classes is useful for bundling 0 or more heterogeneous data types
// into a single variable. The advantage of this is that it greatly simplifies
// function objects that need to take an arbitrary number of parameters; see
// RunnableMethod and IPC::MessageWithTuple.
//
// Tuple<> is supplied to act as a 'void' type. It can be used, for example,
// when dispatching to a function that accepts no arguments (see the
// Dispatchers below).
// Tuple<A> is rarely useful. One such use is when A is non-const ref that you
// want filled by the dispatchee, and the tuple is merely a container for that
// output (a "tier"). See MakeRefTuple and its usages.

template <typename... Ts>
using Tuple = std::tuple<Ts...>;

using std::get;

// Tuple creators -------------------------------------------------------------
//
// Helper functions for constructing tuples while inferring the template
// argument types.

template <typename... Ts>
inline Tuple<Ts...> MakeTuple(const Ts&... arg) {
return Tuple<Ts...>(arg...);
}

// The following set of helpers make what Boost refers to as "Tiers" - a tuple
// of references.

template <typename... Ts>
inline Tuple<Ts&...> MakeRefTuple(Ts&... arg) {
return Tuple<Ts&...>(arg...);
}

// Dispatchers ----------------------------------------------------------------
//
// Helper functions that call the given method on an object, with the unpacked
Expand All @@ -161,29 +121,30 @@ inline Tuple<Ts&...> MakeRefTuple(Ts&... arg) {
template <typename ObjT, typename Method, typename... Ts, size_t... Ns>
inline void DispatchToMethodImpl(const ObjT& obj,
Method method,
const Tuple<Ts...>& arg,
const std::tuple<Ts...>& arg,
IndexSequence<Ns...>) {
(obj->*method)(internal::Unwrap(get<Ns>(arg))...);
(obj->*method)(internal::Unwrap(std::get<Ns>(arg))...);
}

template <typename ObjT, typename Method, typename... Ts>
inline void DispatchToMethod(const ObjT& obj,
Method method,
const Tuple<Ts...>& arg) {
const std::tuple<Ts...>& arg) {
DispatchToMethodImpl(obj, method, arg, MakeIndexSequence<sizeof...(Ts)>());
}

// Static Dispatchers with no out params.

template <typename Function, typename... Ts, size_t... Ns>
inline void DispatchToFunctionImpl(Function function,
const Tuple<Ts...>& arg,
const std::tuple<Ts...>& arg,
IndexSequence<Ns...>) {
(*function)(internal::Unwrap(get<Ns>(arg))...);
(*function)(internal::Unwrap(std::get<Ns>(arg))...);
}

template <typename Function, typename... Ts>
inline void DispatchToFunction(Function function, const Tuple<Ts...>& arg) {
inline void DispatchToFunction(Function function,
const std::tuple<Ts...>& arg) {
DispatchToFunctionImpl(function, arg, MakeIndexSequence<sizeof...(Ts)>());
}

Expand All @@ -197,18 +158,19 @@ template <typename ObjT,
size_t... OutNs>
inline void DispatchToMethodImpl(const ObjT& obj,
Method method,
const Tuple<InTs...>& in,
Tuple<OutTs...>* out,
const std::tuple<InTs...>& in,
std::tuple<OutTs...>* out,
IndexSequence<InNs...>,
IndexSequence<OutNs...>) {
(obj->*method)(internal::Unwrap(get<InNs>(in))..., &get<OutNs>(*out)...);
(obj->*method)(internal::Unwrap(std::get<InNs>(in))...,
&std::get<OutNs>(*out)...);
}

template <typename ObjT, typename Method, typename... InTs, typename... OutTs>
inline void DispatchToMethod(const ObjT& obj,
Method method,
const Tuple<InTs...>& in,
Tuple<OutTs...>* out) {
const std::tuple<InTs...>& in,
std::tuple<OutTs...>* out) {
DispatchToMethodImpl(obj, method, in, out,
MakeIndexSequence<sizeof...(InTs)>(),
MakeIndexSequence<sizeof...(OutTs)>());
Expand Down
55 changes: 19 additions & 36 deletions base/tuple_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,51 +32,34 @@ struct Addz {
} // namespace

TEST(TupleTest, Basic) {
base::Tuple<> t0 = base::MakeTuple();
std::tuple<> t0 = std::make_tuple();
ALLOW_UNUSED_LOCAL(t0);
base::Tuple<int> t1(1);
base::Tuple<int, const char*> t2 =
base::MakeTuple(1, static_cast<const char*>("wee"));
base::Tuple<int, int, int> t3(1, 2, 3);
base::Tuple<int, int, int, int*> t4(1, 2, 3, &get<0>(t1));
base::Tuple<int, int, int, int, int*> t5(1, 2, 3, 4, &get<0>(t4));
base::Tuple<int, int, int, int, int, int*> t6(1, 2, 3, 4, 5, &get<0>(t4));

EXPECT_EQ(1, get<0>(t1));
EXPECT_EQ(1, get<0>(t2));
EXPECT_EQ(1, get<0>(t3));
EXPECT_EQ(2, get<1>(t3));
EXPECT_EQ(3, get<2>(t3));
EXPECT_EQ(1, get<0>(t4));
EXPECT_EQ(2, get<1>(t4));
EXPECT_EQ(3, get<2>(t4));
EXPECT_EQ(1, get<0>(t5));
EXPECT_EQ(2, get<1>(t5));
EXPECT_EQ(3, get<2>(t5));
EXPECT_EQ(4, get<3>(t5));
EXPECT_EQ(1, get<0>(t6));
EXPECT_EQ(2, get<1>(t6));
EXPECT_EQ(3, get<2>(t6));
EXPECT_EQ(4, get<3>(t6));
EXPECT_EQ(5, get<4>(t6));

EXPECT_EQ(1, get<0>(t1));
std::tuple<int> t1(1);
std::tuple<int, const char*> t2 =
std::make_tuple(1, static_cast<const char*>("wee"));
ALLOW_UNUSED_LOCAL(t2);
std::tuple<int, int, int> t3(1, 2, 3);
std::tuple<int, int, int, int*> t4(1, 2, 3, &std::get<0>(t1));
std::tuple<int, int, int, int, int*> t5(1, 2, 3, 4, &std::get<0>(t4));
std::tuple<int, int, int, int, int, int*> t6(1, 2, 3, 4, 5, &std::get<0>(t4));

EXPECT_EQ(1, std::get<0>(t1));
DispatchToFunction(&DoAdd, t4);
EXPECT_EQ(6, get<0>(t1));
EXPECT_EQ(6, std::get<0>(t1));

int res = 0;
DispatchToFunction(&DoAdd, base::MakeTuple(9, 8, 7, &res));
DispatchToFunction(&DoAdd, std::make_tuple(9, 8, 7, &res));
EXPECT_EQ(24, res);

Addy addy;
EXPECT_EQ(1, get<0>(t4));
EXPECT_EQ(1, std::get<0>(t4));
DispatchToMethod(&addy, &Addy::DoAdd, t5);
EXPECT_EQ(10, get<0>(t4));
EXPECT_EQ(10, std::get<0>(t4));

Addz addz;
EXPECT_EQ(10, get<0>(t4));
EXPECT_EQ(10, std::get<0>(t4));
DispatchToMethod(&addz, &Addz::DoAdd, t6);
EXPECT_EQ(15, get<0>(t4));
EXPECT_EQ(15, std::get<0>(t4));
}

namespace {
Expand Down Expand Up @@ -111,8 +94,8 @@ TEST(TupleTest, Copying) {
bool res = false;

// Creating the tuple should copy the class to store internally in the tuple.
base::Tuple<CopyLogger, CopyLogger*, bool*> tuple(logger, &logger, &res);
get<1>(tuple) = &get<0>(tuple);
std::tuple<CopyLogger, CopyLogger*, bool*> tuple(logger, &logger, &res);
std::get<1>(tuple) = &std::get<0>(tuple);
EXPECT_EQ(2, CopyLogger::TimesConstructed);
EXPECT_EQ(1, CopyLogger::TimesCopied);

Expand Down
4 changes: 3 additions & 1 deletion chrome/renderer/chrome_render_frame_observer_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "chrome/renderer/chrome_render_frame_observer.h"

#include <tuple>

#include "base/test/histogram_tester.h"
#include "chrome/test/base/chrome_render_view_test.h"
#include "components/translate/content/common/translate_messages.h"
Expand Down Expand Up @@ -31,7 +33,7 @@ TEST_F(ChromeRenderFrameObserverTest, SkipCapturingSubFrames) {
ASSERT_NE(static_cast<IPC::Message*>(NULL), message);
ChromeFrameHostMsg_TranslateLanguageDetermined::Param params;
ChromeFrameHostMsg_TranslateLanguageDetermined::Read(message, &params);
EXPECT_TRUE(base::get<1>(params)) << "Page should be translatable.";
EXPECT_TRUE(std::get<1>(params)) << "Page should be translatable.";
// Should have 2 samples: one for preliminary capture, one for final capture.
// If there are more, then subframes are being captured more than once.
histogram_tester.ExpectTotalCount(kTranslateCaptureText, 2);
Expand Down
34 changes: 17 additions & 17 deletions content/browser/blob_storage/blob_dispatcher_host_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include "content/browser/blob_storage/blob_dispatcher_host.h"

#include <memory>
#include <tuple>
#include <vector>

#include "base/command_line.h"
#include "base/memory/shared_memory.h"
#include "base/run_loop.h"
#include "base/tuple.h"
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
#include "content/common/fileapi/webblob_messages.h"
#include "content/public/common/content_switches.h"
Expand Down Expand Up @@ -185,13 +185,13 @@ class BlobDispatcherHostTest : public testing::Test {
const IPC::Message* message =
sink_.GetUniqueMessageMatching(BlobStorageMsg_RequestMemoryItem::ID);
ASSERT_TRUE(message);
base::Tuple<std::string, std::vector<storage::BlobItemBytesRequest>,
std::vector<base::SharedMemoryHandle>,
std::vector<IPC::PlatformFileForTransit>>
std::tuple<std::string, std::vector<storage::BlobItemBytesRequest>,
std::vector<base::SharedMemoryHandle>,
std::vector<IPC::PlatformFileForTransit>>
args;
BlobStorageMsg_RequestMemoryItem::Read(message, &args);
EXPECT_EQ(expected_uuid, base::get<0>(args));
std::vector<BlobItemBytesRequest> requests = base::get<1>(args);
EXPECT_EQ(expected_uuid, std::get<0>(args));
std::vector<BlobItemBytesRequest> requests = std::get<1>(args);
ASSERT_EQ(requests.size(), expected_requests.size());
for (size_t i = 0; i < expected_requests.size(); ++i) {
EXPECT_EQ(expected_requests[i], requests[i]);
Expand All @@ -209,18 +209,18 @@ class BlobDispatcherHostTest : public testing::Test {
const IPC::Message* message =
sink_.GetUniqueMessageMatching(BlobStorageMsg_RequestMemoryItem::ID);
ASSERT_TRUE(message);
base::Tuple<std::string, std::vector<storage::BlobItemBytesRequest>,
std::vector<base::SharedMemoryHandle>,
std::vector<IPC::PlatformFileForTransit>>
std::tuple<std::string, std::vector<storage::BlobItemBytesRequest>,
std::vector<base::SharedMemoryHandle>,
std::vector<IPC::PlatformFileForTransit>>
args;
BlobStorageMsg_RequestMemoryItem::Read(message, &args);
EXPECT_EQ(expected_uuid, base::get<0>(args));
std::vector<BlobItemBytesRequest> requests = base::get<1>(args);
EXPECT_EQ(expected_uuid, std::get<0>(args));
std::vector<BlobItemBytesRequest> requests = std::get<1>(args);
ASSERT_EQ(requests.size(), expected_requests.size());
for (size_t i = 0; i < expected_requests.size(); ++i) {
EXPECT_EQ(expected_requests[i], requests[i]);
}
*shared_memory_handles = std::move(base::get<2>(args));
*shared_memory_handles = std::move(std::get<2>(args));
}

void ExpectCancel(const std::string& expected_uuid,
Expand All @@ -232,10 +232,10 @@ class BlobDispatcherHostTest : public testing::Test {
const IPC::Message* message =
sink_.GetUniqueMessageMatching(BlobStorageMsg_CancelBuildingBlob::ID);
ASSERT_TRUE(message);
base::Tuple<std::string, IPCBlobCreationCancelCode> args;
std::tuple<std::string, IPCBlobCreationCancelCode> args;
BlobStorageMsg_CancelBuildingBlob::Read(message, &args);
EXPECT_EQ(expected_uuid, base::get<0>(args));
EXPECT_EQ(code, base::get<1>(args));
EXPECT_EQ(expected_uuid, std::get<0>(args));
EXPECT_EQ(code, std::get<1>(args));
}

void ExpectDone(const std::string& expected_uuid) {
Expand All @@ -245,9 +245,9 @@ class BlobDispatcherHostTest : public testing::Test {
sink_.GetFirstMessageMatching(BlobStorageMsg_CancelBuildingBlob::ID));
const IPC::Message* message =
sink_.GetUniqueMessageMatching(BlobStorageMsg_DoneBuildingBlob::ID);
base::Tuple<std::string> args;
std::tuple<std::string> args;
BlobStorageMsg_DoneBuildingBlob::Read(message, &args);
EXPECT_EQ(expected_uuid, base::get<0>(args));
EXPECT_EQ(expected_uuid, std::get<0>(args));
}

bool IsBeingBuiltInHost(const std::string& uuid) {
Expand Down
8 changes: 4 additions & 4 deletions content/browser/devtools/render_frame_devtools_agent_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "content/browser/devtools/render_frame_devtools_agent_host.h"

#include <tuple>
#include <utility>

#include "base/lazy_instance.h"
Expand Down Expand Up @@ -854,13 +855,12 @@ void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame(
if (!ViewHostMsg_SwapCompositorFrame::Read(&message, &param))
return;
if (page_handler_)
page_handler_->OnSwapCompositorFrame(base::get<1>(param).metadata);
page_handler_->OnSwapCompositorFrame(std::get<1>(param).metadata);
if (input_handler_)
input_handler_->OnSwapCompositorFrame(base::get<1>(param).metadata);
input_handler_->OnSwapCompositorFrame(std::get<1>(param).metadata);
if (frame_trace_recorder_ && tracing_handler_->did_initiate_recording()) {
frame_trace_recorder_->OnSwapCompositorFrame(
current_ ? current_->host() : nullptr,
base::get<1>(param).metadata);
current_ ? current_->host() : nullptr, std::get<1>(param).metadata);
}
}

Expand Down
Loading

0 comments on commit 1068f1b

Please sign in to comment.