OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ |
7 | 7 |
8 #include <type_traits> | 8 #include <type_traits> |
9 | 9 |
10 #include "base/template_util.h" | |
11 | |
10 namespace mojo { | 12 namespace mojo { |
11 namespace internal { | 13 namespace internal { |
12 | 14 |
13 template <class T, T v> | 15 template <class T, T v> |
14 struct IntegralConstant { | 16 struct IntegralConstant { |
15 static const T value = v; | 17 static const T value = v; |
16 }; | 18 }; |
17 | 19 |
18 template <class T, T v> | 20 template <class T, T v> |
19 const T IntegralConstant<T, v>::value; | 21 const T IntegralConstant<T, v>::value; |
(...skipping 25 matching lines...) Expand all Loading... | |
45 | 47 |
46 struct NoType { | 48 struct NoType { |
47 YesType dummy[2]; | 49 YesType dummy[2]; |
48 }; | 50 }; |
49 | 51 |
50 // A helper template to determine if given type is non-const move-only-type, | 52 // A helper template to determine if given type is non-const move-only-type, |
51 // i.e. if a value of the given type should be passed via std::move() in a | 53 // i.e. if a value of the given type should be passed via std::move() in a |
52 // destructive way. | 54 // destructive way. |
53 template <typename T> | 55 template <typename T> |
54 struct IsMoveOnlyType { | 56 struct IsMoveOnlyType { |
55 template <typename U> | 57 static const bool value =base::is_move_assignable<T>::value && |
Nico
2016/06/06 18:21:53
i suppose this is clang-format getting this wrong?
dcheng
2016/06/06 18:26:42
Oops, this is me forgetting to upload the clang fo
| |
56 static YesType Test(const typename U::MoveOnlyTypeForCPP03*); | 58 !base::is_copy_assignable<T>::value; |
57 | |
58 template <typename U> | |
59 static NoType Test(...); | |
60 | |
61 static const bool value = | |
62 sizeof(Test<T>(0)) == sizeof(YesType) && !IsConst<T>::value; | |
63 }; | 59 }; |
64 | 60 |
65 // This goop is a trick used to implement a template that can be used to | 61 // This goop is a trick used to implement a template that can be used to |
66 // determine if a given class is the base class of another given class. | 62 // determine if a given class is the base class of another given class. |
67 template <typename, typename> | 63 template <typename, typename> |
68 struct IsSame { | 64 struct IsSame { |
69 static bool const value = false; | 65 static bool const value = false; |
70 }; | 66 }; |
71 template <typename A> | 67 template <typename A> |
72 struct IsSame<A, A> { | 68 struct IsSame<A, A> { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 template <typename T, | 161 template <typename T, |
166 typename std::enable_if<!HasEqualsMethod<T>::value>::type* = nullptr> | 162 typename std::enable_if<!HasEqualsMethod<T>::value>::type* = nullptr> |
167 bool Equals(const T& a, const T& b) { | 163 bool Equals(const T& a, const T& b) { |
168 return a == b; | 164 return a == b; |
169 } | 165 } |
170 | 166 |
171 } // namespace internal | 167 } // namespace internal |
172 } // namespace mojo | 168 } // namespace mojo |
173 | 169 |
174 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ | 170 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ |
OLD | NEW |