| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 23 // | 23 // |
| 24 // struct { void SomeMeth(int a, int b, int c) { } } foo; | 24 // struct { void SomeMeth(int a, int b, int c) { } } foo; |
| 25 // DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3)); | 25 // DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3)); |
| 26 // // foo->SomeMeth(1, 2, 3); | 26 // // foo->SomeMeth(1, 2, 3); |
| 27 | 27 |
| 28 #ifndef BASE_TUPLE_H_ | 28 #ifndef BASE_TUPLE_H_ |
| 29 #define BASE_TUPLE_H_ | 29 #define BASE_TUPLE_H_ |
| 30 | 30 |
| 31 #include "base/bind_helpers.h" | 31 #include "base/bind_helpers.h" |
| 32 | 32 |
| 33 namespace base { |
| 34 |
| 33 // Index sequences | 35 // Index sequences |
| 34 // | 36 // |
| 35 // Minimal clone of the similarly-named C++14 functionality. | 37 // Minimal clone of the similarly-named C++14 functionality. |
| 36 | 38 |
| 37 template <size_t...> | 39 template <size_t...> |
| 38 struct IndexSequence {}; | 40 struct IndexSequence {}; |
| 39 | 41 |
| 40 template <size_t... Ns> | 42 template <size_t... Ns> |
| 41 struct MakeIndexSequenceImpl; | 43 struct MakeIndexSequenceImpl; |
| 42 | 44 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 const T& get() const { return x; } | 176 const T& get() const { return x; } |
| 175 | 177 |
| 176 T x; | 178 T x; |
| 177 }; | 179 }; |
| 178 | 180 |
| 179 // Tuple getters -------------------------------------------------------------- | 181 // Tuple getters -------------------------------------------------------------- |
| 180 // | 182 // |
| 181 // Allows accessing an arbitrary tuple element by index. | 183 // Allows accessing an arbitrary tuple element by index. |
| 182 // | 184 // |
| 183 // Example usage: | 185 // Example usage: |
| 184 // Tuple<int, double> t2; | 186 // base::Tuple<int, double> t2; |
| 185 // get<0>(t2) = 42; | 187 // base::get<0>(t2) = 42; |
| 186 // get<1>(t2) = 3.14; | 188 // base::get<1>(t2) = 3.14; |
| 187 | 189 |
| 188 template <size_t I, typename T> | 190 template <size_t I, typename T> |
| 189 T& get(TupleLeaf<I, T>& leaf) { | 191 T& get(TupleLeaf<I, T>& leaf) { |
| 190 return leaf.get(); | 192 return leaf.get(); |
| 191 } | 193 } |
| 192 | 194 |
| 193 template <size_t I, typename T> | 195 template <size_t I, typename T> |
| 194 const T& get(const TupleLeaf<I, T>& leaf) { | 196 const T& get(const TupleLeaf<I, T>& leaf) { |
| 195 return leaf.get(); | 197 return leaf.get(); |
| 196 } | 198 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 template <typename ObjT, typename Method, typename... InTs, typename... OutTs> | 324 template <typename ObjT, typename Method, typename... InTs, typename... OutTs> |
| 323 inline void DispatchToMethod(ObjT* obj, | 325 inline void DispatchToMethod(ObjT* obj, |
| 324 Method method, | 326 Method method, |
| 325 const Tuple<InTs...>& in, | 327 const Tuple<InTs...>& in, |
| 326 Tuple<OutTs...>* out) { | 328 Tuple<OutTs...>* out) { |
| 327 DispatchToMethodImpl(obj, method, in, out, | 329 DispatchToMethodImpl(obj, method, in, out, |
| 328 MakeIndexSequence<sizeof...(InTs)>(), | 330 MakeIndexSequence<sizeof...(InTs)>(), |
| 329 MakeIndexSequence<sizeof...(OutTs)>()); | 331 MakeIndexSequence<sizeof...(OutTs)>()); |
| 330 } | 332 } |
| 331 | 333 |
| 334 } // namespace base |
| 335 |
| 332 #endif // BASE_TUPLE_H_ | 336 #endif // BASE_TUPLE_H_ |
| OLD | NEW |