OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef SERVICES_FILES_C_LIB_TEMPLATE_UTIL_H_ | |
6 #define SERVICES_FILES_C_LIB_TEMPLATE_UTIL_H_ | |
7 | |
8 namespace mojio { | |
9 | |
10 // TODO(vtl): Stuff copied from mojo/public/cpp/bindings/lib/template_util.h. | |
11 template <class T, T v> | |
12 struct IntegralConstant { | |
13 static const T value = v; | |
14 }; | |
15 | |
16 template <class T, T v> | |
17 const T IntegralConstant<T, v>::value; | |
18 | |
19 typedef IntegralConstant<bool, true> TrueType; | |
20 typedef IntegralConstant<bool, false> FalseType; | |
21 | |
22 template <class T> | |
23 struct IsConst : FalseType {}; | |
24 template <class T> | |
25 struct IsConst<const T> : TrueType {}; | |
26 | |
27 template <bool B, typename T = void> | |
28 struct EnableIf {}; | |
29 | |
30 template <typename T> | |
31 struct EnableIf<true, T> { | |
32 typedef T type; | |
33 }; | |
34 | |
35 typedef char YesType; | |
36 | |
37 struct NoType { | |
38 YesType dummy[2]; | |
39 }; | |
40 | |
41 template <typename T> | |
42 struct IsMoveOnlyType { | |
43 template <typename U> | |
44 static YesType Test(const typename U::MoveOnlyTypeForCPP03*); | |
45 | |
46 template <typename U> | |
47 static NoType Test(...); | |
48 | |
49 static const bool value = | |
50 sizeof(Test<T>(0)) == sizeof(YesType) && !IsConst<T>::value; | |
51 }; | |
52 | |
53 template <typename T> | |
54 typename EnableIf<!IsMoveOnlyType<T>::value, T>::type& Forward(T& t) { | |
55 return t; | |
56 } | |
57 | |
58 template <typename T> | |
59 typename EnableIf<IsMoveOnlyType<T>::value, T>::type Forward(T& t) { | |
60 return t.Pass(); | |
61 } | |
62 // TODO(vtl): (End of stuff copied from template_util.h.) | |
63 | |
64 template <typename T1> | |
65 mojo::Callback<void(T1)> Capture(T1* t1) { | |
66 return [t1](T1 got_t1) { *t1 = Forward(got_t1); }; | |
67 } | |
68 | |
69 template <typename T1, typename T2> | |
70 mojo::Callback<void(T1, T2)> Capture(T1* t1, T2* t2) { | |
71 return [t1, t2](T1 got_t1, T2 got_t2) { | |
72 *t1 = Forward(got_t1); | |
73 *t2 = Forward(got_t2); | |
74 }; | |
75 } | |
76 | |
77 } // namespace mojio | |
78 | |
79 #endif // SERVICES_FILES_C_LIB_TEMPLATE_UTIL_H_ | |
OLD | NEW |