| 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 // Use std::tuple as tuple type. This file contains helper functions for | 5 // Use std::tuple as tuple type. This file contains helper functions for |
| 6 // working with std::tuples. | 6 // working with std::tuples. |
| 7 // The functions DispatchToMethod and DispatchToFunction take a function pointer | 7 // The functions DispatchToMethod and DispatchToFunction take a function pointer |
| 8 // or instance and method pointer, and unpack a tuple into arguments to the | 8 // or instance and method pointer, and unpack a tuple into arguments to the |
| 9 // call. | 9 // 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(OS_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(OS_WIN) && defined(_PREFAST_) | |
| 105 | |
| 106 // std::get() in <=libstdc++-4.6 returns an lvalue-reference for | 54 // std::get() in <=libstdc++-4.6 returns an lvalue-reference for |
| 107 // rvalue-reference of a tuple, where an rvalue-reference is expected. | 55 // rvalue-reference of a tuple, where an rvalue-reference is expected. |
| 108 template <size_t I, typename... Ts> | 56 template <size_t I, typename... Ts> |
| 109 typename std::tuple_element<I, std::tuple<Ts...>>::type&& get( | 57 typename std::tuple_element<I, std::tuple<Ts...>>::type&& get( |
| 110 std::tuple<Ts...>&& t) { | 58 std::tuple<Ts...>&& t) { |
| 111 using ElemType = typename std::tuple_element<I, std::tuple<Ts...>>::type; | 59 using ElemType = typename std::tuple_element<I, std::tuple<Ts...>>::type; |
| 112 return std::forward<ElemType>(std::get<I>(t)); | 60 return std::forward<ElemType>(std::get<I>(t)); |
| 113 } | 61 } |
| 114 | 62 |
| 115 template <size_t I, typename T> | 63 template <size_t I, typename T> |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 InTuple&& in, | 138 InTuple&& in, |
| 191 OutTuple* out) { | 139 OutTuple* out) { |
| 192 DispatchToMethodImpl(obj, method, std::forward<InTuple>(in), out, | 140 DispatchToMethodImpl(obj, method, std::forward<InTuple>(in), out, |
| 193 MakeIndexSequenceForTuple<InTuple>(), | 141 MakeIndexSequenceForTuple<InTuple>(), |
| 194 MakeIndexSequenceForTuple<OutTuple>()); | 142 MakeIndexSequenceForTuple<OutTuple>()); |
| 195 } | 143 } |
| 196 | 144 |
| 197 } // namespace base | 145 } // namespace base |
| 198 | 146 |
| 199 #endif // BASE_TUPLE_H_ | 147 #endif // BASE_TUPLE_H_ |
| OLD | NEW |