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

Side by Side Diff: mojo/public/cpp/bindings/lib/template_util.h

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2014 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 MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_
7
8 #include <type_traits>
9
10 namespace mojo {
11 namespace internal {
12
13 // Types YesType and NoType are guaranteed such that sizeof(YesType) <
14 // sizeof(NoType).
15 typedef char YesType;
16
17 struct NoType {
18 YesType dummy[2];
19 };
20
21 // A helper template to determine if given type is non-const move-only-type,
22 // i.e. if a value of the given type should be passed via .Pass() in a
23 // destructive way.
24 template <typename T>
25 struct IsMoveOnlyType {
26 template <typename U>
27 static YesType Test(const typename U::MoveOnlyTypeForCPP03*);
28
29 template <typename U>
30 static NoType Test(...);
31
32 static const bool value =
33 sizeof(Test<T>(0)) == sizeof(YesType) && !std::is_const<T>::value;
34 };
35
36 // Returns a reference to |t| when T is not a move-only type.
37 template <typename T>
38 typename std::enable_if<!IsMoveOnlyType<T>::value, T>::type& Forward(T& t) {
39 return t;
40 }
41
42 // Returns the result of t.Pass() when T is a move-only type.
43 template <typename T>
44 typename std::enable_if<IsMoveOnlyType<T>::value, T>::type Forward(T& t) {
45 return t.Pass();
46 }
47
48 template <template <typename...> class Template, typename T>
49 struct IsSpecializationOf : std::false_type {};
50
51 template <template <typename...> class Template, typename... Args>
52 struct IsSpecializationOf<Template, Template<Args...>> : std::true_type {};
53
54 } // namespace internal
55 } // namespace mojo
56
57 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/synchronous_connector.cc ('k') | mojo/public/cpp/bindings/lib/union_accessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698