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

Side by Side Diff: mojo/services/files/public/c/lib/template_util.h

Issue 1388413005: Move //mojo/services/X/public/... to //mojo/services/X/... (part 1). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 months 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 | « mojo/services/files/public/c/lib/singletons.cc ('k') | mojo/services/files/public/c/lib/util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« no previous file with comments | « mojo/services/files/public/c/lib/singletons.cc ('k') | mojo/services/files/public/c/lib/util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698