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

Side by Side Diff: base/tuple.h

Issue 2513363003: repro for crbug.com/663886
Patch Set: Created 4 years, 1 month 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 | « base/test/test_suite.cc ('k') | build/android/adb_gdb » ('j') | 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 // 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 10 matching lines...) Expand all
21 // struct { void SomeMeth(int a, int b, int c) { } } foo; 21 // struct { void SomeMeth(int a, int b, int c) { } } foo;
22 // DispatchToMethod(&foo, &Foo::SomeMeth, std::make_tuple(1, 2, 3)); 22 // DispatchToMethod(&foo, &Foo::SomeMeth, std::make_tuple(1, 2, 3));
23 // // foo->SomeMeth(1, 2, 3); 23 // // foo->SomeMeth(1, 2, 3);
24 24
25 #ifndef BASE_TUPLE_H_ 25 #ifndef BASE_TUPLE_H_
26 #define BASE_TUPLE_H_ 26 #define BASE_TUPLE_H_
27 27
28 #include <stddef.h> 28 #include <stddef.h>
29 #include <tuple> 29 #include <tuple>
30 30
31 #include "base/bind_helpers.h"
32 #include "build/build_config.h" 31 #include "build/build_config.h"
33 32
34 namespace base { 33 namespace base {
35 34
36 // Index sequences 35 // Index sequences
37 // 36 //
38 // Minimal clone of the similarly-named C++14 functionality. 37 // Minimal clone of the similarly-named C++14 functionality.
39 38
40 template <size_t...> 39 template <size_t...>
41 struct IndexSequence {}; 40 struct IndexSequence {};
42 41
43 template <size_t... Ns> 42 template <size_t... Ns>
44 struct MakeIndexSequenceImpl; 43 struct MakeIndexSequenceImpl;
45 44
46 #if defined(_PREFAST_) && defined(OS_WIN)
47
48 // Work around VC++ 2013 /analyze internal compiler error:
49 // https://connect.microsoft.com/VisualStudio/feedback/details/1053626
50
51 template <> struct MakeIndexSequenceImpl<0> {
52 using Type = IndexSequence<>;
53 };
54 template <> struct MakeIndexSequenceImpl<1> {
55 using Type = IndexSequence<0>;
56 };
57 template <> struct MakeIndexSequenceImpl<2> {
58 using Type = IndexSequence<0,1>;
59 };
60 template <> struct MakeIndexSequenceImpl<3> {
61 using Type = IndexSequence<0,1,2>;
62 };
63 template <> struct MakeIndexSequenceImpl<4> {
64 using Type = IndexSequence<0,1,2,3>;
65 };
66 template <> struct MakeIndexSequenceImpl<5> {
67 using Type = IndexSequence<0,1,2,3,4>;
68 };
69 template <> struct MakeIndexSequenceImpl<6> {
70 using Type = IndexSequence<0,1,2,3,4,5>;
71 };
72 template <> struct MakeIndexSequenceImpl<7> {
73 using Type = IndexSequence<0,1,2,3,4,5,6>;
74 };
75 template <> struct MakeIndexSequenceImpl<8> {
76 using Type = IndexSequence<0,1,2,3,4,5,6,7>;
77 };
78 template <> struct MakeIndexSequenceImpl<9> {
79 using Type = IndexSequence<0,1,2,3,4,5,6,7,8>;
80 };
81 template <> struct MakeIndexSequenceImpl<10> {
82 using Type = IndexSequence<0,1,2,3,4,5,6,7,8,9>;
83 };
84 template <> struct MakeIndexSequenceImpl<11> {
85 using Type = IndexSequence<0,1,2,3,4,5,6,7,8,9,10>;
86 };
87 template <> struct MakeIndexSequenceImpl<12> {
88 using Type = IndexSequence<0,1,2,3,4,5,6,7,8,9,10,11>;
89 };
90 template <> struct MakeIndexSequenceImpl<13> {
91 using Type = IndexSequence<0,1,2,3,4,5,6,7,8,9,10,11,12>;
92 };
93
94 #else // defined(OS_WIN) && defined(_PREFAST_)
95
96 template <size_t... Ns> 45 template <size_t... Ns>
97 struct MakeIndexSequenceImpl<0, Ns...> { 46 struct MakeIndexSequenceImpl<0, Ns...> {
98 using Type = IndexSequence<Ns...>; 47 using Type = IndexSequence<Ns...>;
99 }; 48 };
100 49
101 template <size_t N, size_t... Ns> 50 template <size_t N, size_t... Ns>
102 struct MakeIndexSequenceImpl<N, Ns...> 51 struct MakeIndexSequenceImpl<N, Ns...>
103 : MakeIndexSequenceImpl<N - 1, N - 1, Ns...> {}; 52 : MakeIndexSequenceImpl<N - 1, N - 1, Ns...> {};
104 53
105 #endif // defined(OS_WIN) && defined(_PREFAST_)
106
107 // std::get() in <=libstdc++-4.6 returns an lvalue-reference for 54 // std::get() in <=libstdc++-4.6 returns an lvalue-reference for
108 // rvalue-reference of a tuple, where an rvalue-reference is expected. 55 // rvalue-reference of a tuple, where an rvalue-reference is expected.
109 template <size_t I, typename... Ts> 56 template <size_t I, typename... Ts>
110 typename std::tuple_element<I, std::tuple<Ts...>>::type&& get( 57 typename std::tuple_element<I, std::tuple<Ts...>>::type&& get(
111 std::tuple<Ts...>&& t) { 58 std::tuple<Ts...>&& t) {
112 using ElemType = typename std::tuple_element<I, std::tuple<Ts...>>::type; 59 using ElemType = typename std::tuple_element<I, std::tuple<Ts...>>::type;
113 return std::forward<ElemType>(std::get<I>(t)); 60 return std::forward<ElemType>(std::get<I>(t));
114 } 61 }
115 62
116 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
191 InTuple&& in, 138 InTuple&& in,
192 OutTuple* out) { 139 OutTuple* out) {
193 DispatchToMethodImpl(obj, method, std::forward<InTuple>(in), out, 140 DispatchToMethodImpl(obj, method, std::forward<InTuple>(in), out,
194 MakeIndexSequenceForTuple<InTuple>(), 141 MakeIndexSequenceForTuple<InTuple>(),
195 MakeIndexSequenceForTuple<OutTuple>()); 142 MakeIndexSequenceForTuple<OutTuple>());
196 } 143 }
197 144
198 } // namespace base 145 } // namespace base
199 146
200 #endif // BASE_TUPLE_H_ 147 #endif // BASE_TUPLE_H_
OLDNEW
« no previous file with comments | « base/test/test_suite.cc ('k') | build/android/adb_gdb » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698