diff options
author | tzik <tzik@chromium.org> | 2016-02-11 02:24:45 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-11 10:26:28 +0000 |
commit | 9ca3021996e87ad03adf4451fd7fc7f8097c8f46 (patch) | |
tree | a1c2fd07c8ea0858cbd6880c834a57ed1a6eadb1 | |
parent | fbcb7dcadf19f4c20217365b3af0a34d66511b49 (diff) | |
download | chromium_src-9ca3021996e87ad03adf4451fd7fc7f8097c8f46.zip chromium_src-9ca3021996e87ad03adf4451fd7fc7f8097c8f46.tar.gz chromium_src-9ca3021996e87ad03adf4451fd7fc7f8097c8f46.tar.bz2 |
Replace base::Tuple implementation with std::tuple
* Remove base::Tuple and make base::Tuple as an alias of std::tuple.
* Expand the alias where it's used in a class template specialization to avoid MSVC2013 internal compiler error.
BUG=554987
Review URL: https://codereview.chromium.org/1673563002
Cr-Commit-Position: refs/heads/master@{#374878}
-rw-r--r-- | base/bind_unittest.cc | 4 | ||||
-rw-r--r-- | base/tuple.h | 55 | ||||
-rw-r--r-- | ipc/ipc_message_utils.h | 24 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_message_utils.h | 10 | ||||
-rw-r--r-- | styleguide/c++/c++11.html | 18 |
5 files changed, 32 insertions, 79 deletions
diff --git a/base/bind_unittest.cc b/base/bind_unittest.cc index d12925a..136cc24 100644 --- a/base/bind_unittest.cc +++ b/base/bind_unittest.cc @@ -334,8 +334,8 @@ TEST_F(BindTest, CurryingRvalueResultOfBind) { // preserve virtual dispatch). TEST_F(BindTest, FunctionTypeSupport) { EXPECT_CALL(static_func_mock_, VoidMethod0()); - EXPECT_CALL(has_ref_, AddRef()).Times(5); - EXPECT_CALL(has_ref_, Release()).Times(5); + EXPECT_CALL(has_ref_, AddRef()).Times(4); + EXPECT_CALL(has_ref_, Release()).Times(4); EXPECT_CALL(has_ref_, VoidMethod0()).Times(2); EXPECT_CALL(has_ref_, VoidConstMethod0()).Times(2); diff --git a/base/tuple.h b/base/tuple.h index e5872cc..e73dd49c 100644 --- a/base/tuple.h +++ b/base/tuple.h @@ -29,6 +29,7 @@ #define BASE_TUPLE_H_ #include <stddef.h> +#include <tuple> #include "base/bind_helpers.h" #include "build/build_config.h" @@ -145,60 +146,10 @@ struct TupleTraits<P&> { // want filled by the dispatchee, and the tuple is merely a container for that // output (a "tier"). See MakeRefTuple and its usages. -template <typename IxSeq, typename... Ts> -struct TupleBaseImpl; template <typename... Ts> -using TupleBase = TupleBaseImpl<MakeIndexSequence<sizeof...(Ts)>, Ts...>; -template <size_t N, typename T> -struct TupleLeaf; +using Tuple = std::tuple<Ts...>; -template <typename... Ts> -struct Tuple final : TupleBase<Ts...> { - Tuple() : TupleBase<Ts...>() {} - explicit Tuple(typename TupleTraits<Ts>::ParamType... args) - : TupleBase<Ts...>(args...) {} -}; - -// Avoids ambiguity between Tuple's two constructors. -template <> -struct Tuple<> final {}; - -template <size_t... Ns, typename... Ts> -struct TupleBaseImpl<IndexSequence<Ns...>, Ts...> : TupleLeaf<Ns, Ts>... { - TupleBaseImpl() : TupleLeaf<Ns, Ts>()... {} - explicit TupleBaseImpl(typename TupleTraits<Ts>::ParamType... args) - : TupleLeaf<Ns, Ts>(args)... {} -}; - -template <size_t N, typename T> -struct TupleLeaf { - TupleLeaf() {} - explicit TupleLeaf(typename TupleTraits<T>::ParamType x) : x(x) {} - - T& get() { return x; } - const T& get() const { return x; } - - T x; -}; - -// Tuple getters -------------------------------------------------------------- -// -// Allows accessing an arbitrary tuple element by index. -// -// Example usage: -// base::Tuple<int, double> t2; -// base::get<0>(t2) = 42; -// base::get<1>(t2) = 3.14; - -template <size_t I, typename T> -T& get(TupleLeaf<I, T>& leaf) { - return leaf.get(); -} - -template <size_t I, typename T> -const T& get(const TupleLeaf<I, T>& leaf) { - return leaf.get(); -} +using std::get; // Tuple types ---------------------------------------------------------------- // diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h index 942a4b7..971370a 100644 --- a/ipc/ipc_message_utils.h +++ b/ipc/ipc_message_utils.h @@ -649,8 +649,8 @@ struct IPC_EXPORT ParamTraits<base::TimeTicks> { }; template <> -struct ParamTraits<base::Tuple<>> { - typedef base::Tuple<> param_type; +struct ParamTraits<std::tuple<>> { + typedef std::tuple<> param_type; static void GetSize(base::PickleSizer* sizer, const param_type& p) {} static void Write(base::Pickle* m, const param_type& p) {} static bool Read(const base::Pickle* m, @@ -663,8 +663,8 @@ struct ParamTraits<base::Tuple<>> { }; template <class A> -struct ParamTraits<base::Tuple<A>> { - typedef base::Tuple<A> param_type; +struct ParamTraits<std::tuple<A>> { + typedef std::tuple<A> param_type; static void GetSize(base::PickleSizer* sizer, const param_type& p) { GetParamSize(sizer, base::get<0>(p)); } @@ -682,8 +682,8 @@ struct ParamTraits<base::Tuple<A>> { }; template <class A, class B> -struct ParamTraits<base::Tuple<A, B>> { - typedef base::Tuple<A, B> param_type; +struct ParamTraits<std::tuple<A, B>> { + typedef std::tuple<A, B> param_type; static void GetSize(base::PickleSizer* sizer, const param_type& p) { GetParamSize(sizer, base::get<0>(p)); GetParamSize(sizer, base::get<1>(p)); @@ -706,8 +706,8 @@ struct ParamTraits<base::Tuple<A, B>> { }; template <class A, class B, class C> -struct ParamTraits<base::Tuple<A, B, C>> { - typedef base::Tuple<A, B, C> param_type; +struct ParamTraits<std::tuple<A, B, C>> { + typedef std::tuple<A, B, C> param_type; static void GetSize(base::PickleSizer* sizer, const param_type& p) { GetParamSize(sizer, base::get<0>(p)); GetParamSize(sizer, base::get<1>(p)); @@ -735,8 +735,8 @@ struct ParamTraits<base::Tuple<A, B, C>> { }; template <class A, class B, class C, class D> -struct ParamTraits<base::Tuple<A, B, C, D>> { - typedef base::Tuple<A, B, C, D> param_type; +struct ParamTraits<std::tuple<A, B, C, D>> { + typedef std::tuple<A, B, C, D> param_type; static void GetSize(base::PickleSizer* sizer, const param_type& p) { GetParamSize(sizer, base::get<0>(p)); GetParamSize(sizer, base::get<1>(p)); @@ -769,8 +769,8 @@ struct ParamTraits<base::Tuple<A, B, C, D>> { }; template <class A, class B, class C, class D, class E> -struct ParamTraits<base::Tuple<A, B, C, D, E>> { - typedef base::Tuple<A, B, C, D, E> param_type; +struct ParamTraits<std::tuple<A, B, C, D, E>> { + typedef std::tuple<A, B, C, D, E> param_type; static void GetSize(base::PickleSizer* sizer, const param_type& p) { GetParamSize(sizer, base::get<0>(p)); GetParamSize(sizer, base::get<1>(p)); diff --git a/ppapi/proxy/ppapi_message_utils.h b/ppapi/proxy/ppapi_message_utils.h index fbcb105..3fdb519 100644 --- a/ppapi/proxy/ppapi_message_utils.h +++ b/ppapi/proxy/ppapi_message_utils.h @@ -22,7 +22,7 @@ struct TupleTypeMatch1 { static const bool kValue = false; }; template <class A> -struct TupleTypeMatch1<base::Tuple<A>, A> { +struct TupleTypeMatch1<std::tuple<A>, A> { static const bool kValue = true; }; @@ -31,7 +31,7 @@ struct TupleTypeMatch2 { static const bool kValue = false; }; template <class A, class B> -struct TupleTypeMatch2<base::Tuple<A, B>, A, B> { +struct TupleTypeMatch2<std::tuple<A, B>, A, B> { static const bool kValue = true; }; @@ -40,7 +40,7 @@ struct TupleTypeMatch3 { static const bool kValue = false; }; template <class A, class B, class C> -struct TupleTypeMatch3<base::Tuple<A, B, C>, A, B, C> { +struct TupleTypeMatch3<std::tuple<A, B, C>, A, B, C> { static const bool kValue = true; }; @@ -49,7 +49,7 @@ struct TupleTypeMatch4 { static const bool kValue = false; }; template <class A, class B, class C, class D> -struct TupleTypeMatch4<base::Tuple<A, B, C, D>, A, B, C, D> { +struct TupleTypeMatch4<std::tuple<A, B, C, D>, A, B, C, D> { static const bool kValue = true; }; @@ -58,7 +58,7 @@ struct TupleTypeMatch5 { static const bool kValue = false; }; template <class A, class B, class C, class D, class E> -struct TupleTypeMatch5<base::Tuple<A, B, C, D, E>, A, B, C, D, E> { +struct TupleTypeMatch5<std::tuple<A, B, C, D, E>, A, B, C, D, E> { static const bool kValue = true; }; diff --git a/styleguide/c++/c++11.html b/styleguide/c++/c++11.html index 27d37b6..7c3a42c 100644 --- a/styleguide/c++/c++11.html +++ b/styleguide/c++/c++11.html @@ -478,6 +478,16 @@ and <a href="http://en.cppreference.com/w/cpp/container/unordered_set">std::unor <td>Per the <a href="https://google.github.io/styleguide/cppguide.html#std_hash">Google style guide</a>, specify custom hashers instead of specializing <code>std::hash</code> for custom types. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/nCdjQqnouO4">Discussion thread</a>.</td> </tr> +<tr> +<td>Tuples</td> +<td><code>std::tuple</code></td> +<td>A fixed-size ordered collection of values of mixed types</td> +<td><a href="http://en.cppreference.com/w/cpp/utility/tuple">std::tuple</a></td> +<td><a href="https://crbug.com/554987">Tracking bug</a> to plan moving from <code>base::Tuple</code> to <code>std::tuple</code>. See also <code>std::tie</code>. +<code>base::Tuple</code> is now an alias for <code>std::tuple</code>. In class template specializations, use <code>std::tuple</code> instead of <code>base::Tuple</code> to work around a MSVS2013 internal compiler error (Error code: C1001). +</td> +</tr> + </tbody> </table> @@ -1026,14 +1036,6 @@ Declaring functions</a></td> </tr> <tr> -<td>Tuples</td> -<td><code>std::tuple</code></td> -<td>A fixed-size ordered collection of values of mixed types</td> -<td><a href="http://en.cppreference.com/w/cpp/utility/tuple">std::tuple</a></td> -<td><a href="https://crbug.com/554987">Tracking bug</a> to plan moving from <code>base::Tuple</code> to <code>std::tuple</code>. See also <code>std::tie</code></td> -</tr> - -<tr> <td>Type-Generic Math Functions</td> <td>Functions within <code><ctgmath></code></td> <td>Provides a means to call real or complex functions |