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

Side by Side Diff: base/tuple.h

Issue 791883003: tuple: leave fields uninitialized in default constructors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix silly syntax error Created 6 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // A Tuple is a generic templatized container, similar in concept to std::pair 5 // A Tuple is a generic templatized container, similar in concept to std::pair
6 // and std::tuple. The convenient MakeTuple() function takes any number of 6 // and std::tuple. The convenient MakeTuple() function takes any number of
7 // arguments and will construct and return the appropriate Tuple object. The 7 // arguments and will construct and return the appropriate Tuple object. The
8 // functions DispatchToMethod and DispatchToFunction take a function pointer or 8 // functions DispatchToMethod and DispatchToFunction take a function pointer or
9 // instance and method pointer, and unpack a tuple into arguments to the call. 9 // instance and method pointer, and unpack a tuple into arguments to the call.
10 // 10 //
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 template <size_t... Ns, typename... Ts> 109 template <size_t... Ns, typename... Ts>
110 struct TupleBaseImpl<IndexSequence<Ns...>, Ts...> : TupleLeaf<Ns, Ts>... { 110 struct TupleBaseImpl<IndexSequence<Ns...>, Ts...> : TupleLeaf<Ns, Ts>... {
111 TupleBaseImpl() : TupleLeaf<Ns, Ts>()... {} 111 TupleBaseImpl() : TupleLeaf<Ns, Ts>()... {}
112 explicit TupleBaseImpl(typename TupleTraits<Ts>::ParamType... args) 112 explicit TupleBaseImpl(typename TupleTraits<Ts>::ParamType... args)
113 : TupleLeaf<Ns, Ts>(args)... {} 113 : TupleLeaf<Ns, Ts>(args)... {}
114 }; 114 };
115 115
116 template <size_t N, typename T> 116 template <size_t N, typename T>
117 struct TupleLeaf { 117 struct TupleLeaf {
118 TupleLeaf() : x() {} 118 TupleLeaf() {}
119 explicit TupleLeaf(typename TupleTraits<T>::ParamType x) : x(x) {} 119 explicit TupleLeaf(typename TupleTraits<T>::ParamType x) : x(x) {}
120 120
121 T& get() { return x; } 121 T& get() { return x; }
122 const T& get() const { return x; } 122 const T& get() const { return x; }
123 123
124 T x; 124 T x;
125 }; 125 };
126 126
127 // For legacy compatibility, we name the first 8 tuple elements "a", "b", ... 127 // For legacy compatibility, we name the first 8 tuple elements "a", "b", ...
128 // TODO(mdempsky): Update users to use get<N>() (crbug.com/440675). 128 // TODO(mdempsky): Update users to use get<N>() (crbug.com/440675).
129 129
130 #define DEFINE_TUPLE_LEAF(N, x) \ 130 #define DEFINE_TUPLE_LEAF(N, x) \
131 template <typename T> \ 131 template <typename T> \
132 struct TupleLeaf<N, T> { \ 132 struct TupleLeaf<N, T> { \
133 TupleLeaf() : x() {} \ 133 TupleLeaf() {} \
134 explicit TupleLeaf(typename TupleTraits<T>::ParamType x) : x(x) {} \ 134 explicit TupleLeaf(typename TupleTraits<T>::ParamType x) : x(x) {} \
135 \ 135 \
136 T& get() { return x; } \ 136 T& get() { return x; } \
137 const T& get() const { return x; } \ 137 const T& get() const { return x; } \
138 \ 138 \
139 T x; \ 139 T x; \
140 } 140 }
141 141
142 DEFINE_TUPLE_LEAF(0, a); 142 DEFINE_TUPLE_LEAF(0, a);
143 DEFINE_TUPLE_LEAF(1, b); 143 DEFINE_TUPLE_LEAF(1, b);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 inline void DispatchToMethod(ObjT* obj, 336 inline void DispatchToMethod(ObjT* obj,
337 Method method, 337 Method method,
338 const Tuple<InTs...>& in, 338 const Tuple<InTs...>& in,
339 Tuple<OutTs...>* out) { 339 Tuple<OutTs...>* out) {
340 DispatchToMethodImpl(obj, method, in, out, 340 DispatchToMethodImpl(obj, method, in, out,
341 MakeIndexSequence<sizeof...(InTs)>(), 341 MakeIndexSequence<sizeof...(InTs)>(),
342 MakeIndexSequence<sizeof...(OutTs)>()); 342 MakeIndexSequence<sizeof...(OutTs)>());
343 } 343 }
344 344
345 #endif // BASE_TUPLE_H__ 345 #endif // BASE_TUPLE_H__
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698