| 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 24 matching lines...) Expand all Loading... |
| 35 // Index sequences | 35 // Index sequences |
| 36 // | 36 // |
| 37 // Minimal clone of the similarly-named C++14 functionality. | 37 // Minimal clone of the similarly-named C++14 functionality. |
| 38 | 38 |
| 39 template <size_t...> | 39 template <size_t...> |
| 40 struct IndexSequence {}; | 40 struct IndexSequence {}; |
| 41 | 41 |
| 42 template <size_t... Ns> | 42 template <size_t... Ns> |
| 43 struct MakeIndexSequenceImpl; | 43 struct MakeIndexSequenceImpl; |
| 44 | 44 |
| 45 #if defined(_PREFAST_) && defined(OS_WIN) | |
| 46 | |
| 47 // Work around VC++ 2013 /analyze internal compiler error: | |
| 48 // https://connect.microsoft.com/VisualStudio/feedback/details/1053626 | |
| 49 | |
| 50 template <> struct MakeIndexSequenceImpl<0> { | |
| 51 using Type = IndexSequence<>; | |
| 52 }; | |
| 53 template <> struct MakeIndexSequenceImpl<1> { | |
| 54 using Type = IndexSequence<0>; | |
| 55 }; | |
| 56 template <> struct MakeIndexSequenceImpl<2> { | |
| 57 using Type = IndexSequence<0,1>; | |
| 58 }; | |
| 59 template <> struct MakeIndexSequenceImpl<3> { | |
| 60 using Type = IndexSequence<0,1,2>; | |
| 61 }; | |
| 62 template <> struct MakeIndexSequenceImpl<4> { | |
| 63 using Type = IndexSequence<0,1,2,3>; | |
| 64 }; | |
| 65 template <> struct MakeIndexSequenceImpl<5> { | |
| 66 using Type = IndexSequence<0,1,2,3,4>; | |
| 67 }; | |
| 68 template <> struct MakeIndexSequenceImpl<6> { | |
| 69 using Type = IndexSequence<0,1,2,3,4,5>; | |
| 70 }; | |
| 71 template <> struct MakeIndexSequenceImpl<7> { | |
| 72 using Type = IndexSequence<0,1,2,3,4,5,6>; | |
| 73 }; | |
| 74 template <> struct MakeIndexSequenceImpl<8> { | |
| 75 using Type = IndexSequence<0,1,2,3,4,5,6,7>; | |
| 76 }; | |
| 77 template <> struct MakeIndexSequenceImpl<9> { | |
| 78 using Type = IndexSequence<0,1,2,3,4,5,6,7,8>; | |
| 79 }; | |
| 80 template <> struct MakeIndexSequenceImpl<10> { | |
| 81 using Type = IndexSequence<0,1,2,3,4,5,6,7,8,9>; | |
| 82 }; | |
| 83 template <> struct MakeIndexSequenceImpl<11> { | |
| 84 using Type = IndexSequence<0,1,2,3,4,5,6,7,8,9,10>; | |
| 85 }; | |
| 86 template <> struct MakeIndexSequenceImpl<12> { | |
| 87 using Type = IndexSequence<0,1,2,3,4,5,6,7,8,9,10,11>; | |
| 88 }; | |
| 89 template <> struct MakeIndexSequenceImpl<13> { | |
| 90 using Type = IndexSequence<0,1,2,3,4,5,6,7,8,9,10,11,12>; | |
| 91 }; | |
| 92 | |
| 93 #else // defined(WIN) && defined(_PREFAST_) | |
| 94 | |
| 95 template <size_t... Ns> | 45 template <size_t... Ns> |
| 96 struct MakeIndexSequenceImpl<0, Ns...> { | 46 struct MakeIndexSequenceImpl<0, Ns...> { |
| 97 using Type = IndexSequence<Ns...>; | 47 using Type = IndexSequence<Ns...>; |
| 98 }; | 48 }; |
| 99 | 49 |
| 100 template <size_t N, size_t... Ns> | 50 template <size_t N, size_t... Ns> |
| 101 struct MakeIndexSequenceImpl<N, Ns...> | 51 struct MakeIndexSequenceImpl<N, Ns...> |
| 102 : MakeIndexSequenceImpl<N - 1, N - 1, Ns...> {}; | 52 : MakeIndexSequenceImpl<N - 1, N - 1, Ns...> {}; |
| 103 | 53 |
| 104 #endif // defined(WIN) && defined(_PREFAST_) | |
| 105 | |
| 106 template <size_t N> | 54 template <size_t N> |
| 107 using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type; | 55 using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type; |
| 108 | 56 |
| 109 // Traits ---------------------------------------------------------------------- | 57 // Traits ---------------------------------------------------------------------- |
| 110 // | 58 // |
| 111 // A simple traits class for tuple arguments. | 59 // A simple traits class for tuple arguments. |
| 112 // | 60 // |
| 113 // ValueType: the bare, nonref version of a type (same as the type for nonrefs). | 61 // ValueType: the bare, nonref version of a type (same as the type for nonrefs). |
| 114 // RefType: the ref version of a type (same as the type for refs). | 62 // RefType: the ref version of a type (same as the type for refs). |
| 115 // ParamType: what type to pass to functions (refs should not be constified). | 63 // ParamType: what type to pass to functions (refs should not be constified). |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 const Tuple<InTs...>& in, | 275 const Tuple<InTs...>& in, |
| 328 Tuple<OutTs...>* out) { | 276 Tuple<OutTs...>* out) { |
| 329 DispatchToMethodImpl(obj, method, in, out, | 277 DispatchToMethodImpl(obj, method, in, out, |
| 330 MakeIndexSequence<sizeof...(InTs)>(), | 278 MakeIndexSequence<sizeof...(InTs)>(), |
| 331 MakeIndexSequence<sizeof...(OutTs)>()); | 279 MakeIndexSequence<sizeof...(OutTs)>()); |
| 332 } | 280 } |
| 333 | 281 |
| 334 } // namespace base | 282 } // namespace base |
| 335 | 283 |
| 336 #endif // BASE_TUPLE_H_ | 284 #endif // BASE_TUPLE_H_ |
| OLD | NEW |