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 22 matching lines...) Expand all Loading... | |
33 // Index sequences | 33 // Index sequences |
34 // | 34 // |
35 // Minimal clone of the similarly-named C++14 functionality. | 35 // Minimal clone of the similarly-named C++14 functionality. |
36 | 36 |
37 template <size_t...> | 37 template <size_t...> |
38 struct IndexSequence {}; | 38 struct IndexSequence {}; |
39 | 39 |
40 template <size_t... Ns> | 40 template <size_t... Ns> |
41 struct MakeIndexSequenceImpl; | 41 struct MakeIndexSequenceImpl; |
42 | 42 |
43 #if defined(_PREFAST_) && defined(OS_WIN) | |
44 | |
45 // Work around VC++ 2013 /analyze internal compiler error: | |
46 // https://connect.microsoft.com/VisualStudio/feedback/details/1053626 | |
47 | |
48 template <> | |
49 struct IndexSequence<0> {}; | |
50 | |
51 template <> | |
52 struct IndexSequence<0,1> {}; | |
53 | |
54 template <> | |
55 struct IndexSequence<0,1,2> {}; | |
56 | |
57 template <> | |
58 struct IndexSequence<0,1,2,3> {}; | |
59 | |
60 template <> | |
61 struct IndexSequence<0,1,2,3,4> {}; | |
62 | |
63 template <> | |
64 struct MakeIndexSequenceImpl<0> { | |
65 using Type = IndexSequence<>; | |
66 }; | |
67 | |
68 template <> | |
69 struct MakeIndexSequenceImpl<1> { | |
70 using Type = IndexSequence<0>; | |
71 }; | |
72 | |
73 template <> | |
74 struct MakeIndexSequenceImpl<2> { | |
75 using Type = IndexSequence<0,1>; | |
76 }; | |
77 | |
78 template <> | |
79 struct MakeIndexSequenceImpl<3> { | |
80 using Type = IndexSequence<0,1,2>; | |
81 }; | |
82 | |
83 template <> | |
84 struct MakeIndexSequenceImpl<4> { | |
85 using Type = IndexSequence<0,1,2,3>; | |
86 }; | |
87 | |
88 template <> | |
89 struct MakeIndexSequenceImpl<5> { | |
90 using Type = IndexSequence<0,1,2,3,4>; | |
91 }; | |
92 | |
93 #else | |
94 | |
43 template <size_t... Ns> | 95 template <size_t... Ns> |
44 struct MakeIndexSequenceImpl<0, Ns...> { | 96 struct MakeIndexSequenceImpl<0, Ns...> { |
45 using Type = IndexSequence<Ns...>; | 97 using Type = IndexSequence<Ns...>; |
46 }; | 98 }; |
47 | 99 |
48 template <size_t N, size_t... Ns> | 100 template <size_t N, size_t... Ns> |
49 struct MakeIndexSequenceImpl<N, Ns...> | 101 struct MakeIndexSequenceImpl<N, Ns...> |
mdempsky
2014/12/15 22:17:55
I previously wrote this as:
template <size_t
| |
50 : MakeIndexSequenceImpl<N - 1, N - 1, Ns...> {}; | 102 : MakeIndexSequenceImpl<N - 1, N - 1, Ns...> {}; |
51 | 103 |
104 #endif | |
105 | |
52 template <size_t N> | 106 template <size_t N> |
53 using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type; | 107 using MakeIndexSequence = typename MakeIndexSequenceImpl<N>::Type; |
54 | 108 |
55 // Traits ---------------------------------------------------------------------- | 109 // Traits ---------------------------------------------------------------------- |
56 // | 110 // |
57 // A simple traits class for tuple arguments. | 111 // A simple traits class for tuple arguments. |
58 // | 112 // |
59 // ValueType: the bare, nonref version of a type (same as the type for nonrefs). | 113 // ValueType: the bare, nonref version of a type (same as the type for nonrefs). |
60 // RefType: the ref version of a type (same as the type for refs). | 114 // RefType: the ref version of a type (same as the type for refs). |
61 // ParamType: what type to pass to functions (refs should not be constified). | 115 // ParamType: what type to pass to functions (refs should not be constified). |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 inline void DispatchToMethod(ObjT* obj, | 390 inline void DispatchToMethod(ObjT* obj, |
337 Method method, | 391 Method method, |
338 const Tuple<InTs...>& in, | 392 const Tuple<InTs...>& in, |
339 Tuple<OutTs...>* out) { | 393 Tuple<OutTs...>* out) { |
340 DispatchToMethodImpl(obj, method, in, out, | 394 DispatchToMethodImpl(obj, method, in, out, |
341 MakeIndexSequence<sizeof...(InTs)>(), | 395 MakeIndexSequence<sizeof...(InTs)>(), |
342 MakeIndexSequence<sizeof...(OutTs)>()); | 396 MakeIndexSequence<sizeof...(OutTs)>()); |
343 } | 397 } |
344 | 398 |
345 #endif // BASE_TUPLE_H__ | 399 #endif // BASE_TUPLE_H__ |
OLD | NEW |