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 namespace mojo { | 10 namespace mojo { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 struct NoType { | 46 struct NoType { |
47 YesType dummy[2]; | 47 YesType dummy[2]; |
48 }; | 48 }; |
49 | 49 |
50 // A helper template to determine if given type is non-const move-only-type, | 50 // 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 | 51 // i.e. if a value of the given type should be passed via std::move() in a |
52 // destructive way. | 52 // destructive way. |
53 template <typename T> | 53 template <typename T> |
54 struct IsMoveOnlyType { | 54 struct IsMoveOnlyType { |
55 template <typename U> | 55 static const bool value = std::is_constructible<T, T&&>::value && |
56 static YesType Test(const typename U::MoveOnlyTypeForCPP03*); | 56 !std::is_constructible<T, const 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 }; | 57 }; |
64 | 58 |
65 // This goop is a trick used to implement a template that can be used to | 59 // 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. | 60 // determine if a given class is the base class of another given class. |
67 template <typename, typename> | 61 template <typename, typename> |
68 struct IsSame { | 62 struct IsSame { |
69 static bool const value = false; | 63 static bool const value = false; |
70 }; | 64 }; |
71 template <typename A> | 65 template <typename A> |
72 struct IsSame<A, A> { | 66 struct IsSame<A, A> { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 template <typename T, | 159 template <typename T, |
166 typename std::enable_if<!HasEqualsMethod<T>::value>::type* = nullptr> | 160 typename std::enable_if<!HasEqualsMethod<T>::value>::type* = nullptr> |
167 bool Equals(const T& a, const T& b) { | 161 bool Equals(const T& a, const T& b) { |
168 return a == b; | 162 return a == b; |
169 } | 163 } |
170 | 164 |
171 } // namespace internal | 165 } // namespace internal |
172 } // namespace mojo | 166 } // namespace mojo |
173 | 167 |
174 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ | 168 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ |
OLD | NEW |