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}
This commit is contained in:
base
ipc
ppapi/proxy
styleguide/c++
@ -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);
|
||||
|
||||
|
55
base/tuple.h
55
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 ----------------------------------------------------------------
|
||||
//
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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>
|
||||
|
||||
@ -1025,14 +1035,6 @@ Declaring functions</a></td>
|
||||
<td><a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/OQyYSfH9m2M">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></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Type-Generic Math Functions</td>
|
||||
<td>Functions within <code><ctgmath></code></td>
|
||||
|
Reference in New Issue
Block a user