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 namespace mojo { | 8 namespace mojo { |
9 namespace internal { | 9 namespace internal { |
10 | 10 |
11 template<class T, T v> | 11 template<class T, T v> |
12 struct IntegralConstant { | 12 struct IntegralConstant { |
13 static const T value = v; | 13 static const T value = v; |
14 }; | 14 }; |
15 | 15 |
16 template <class T, T v> const T IntegralConstant<T, v>::value; | 16 template <class T, T v> const T IntegralConstant<T, v>::value; |
17 | 17 |
18 typedef IntegralConstant<bool, true> TrueType; | 18 typedef IntegralConstant<bool, true> TrueType; |
19 typedef IntegralConstant<bool, false> FalseType; | 19 typedef IntegralConstant<bool, false> FalseType; |
20 | 20 |
21 template <class T> struct IsConst : FalseType {}; | 21 template <class T> struct IsConst : FalseType {}; |
22 template <class T> struct IsConst<const T> : TrueType {}; | 22 template <class T> struct IsConst<const T> : TrueType {}; |
23 | 23 |
24 template <class T> struct IsPointer : FalseType {}; | |
25 template <class T> struct IsPointer<T*> : TrueType {}; | |
26 | |
24 template<bool B, typename T = void> | 27 template<bool B, typename T = void> |
25 struct EnableIf {}; | 28 struct EnableIf {}; |
26 | 29 |
27 template<typename T> | 30 template<typename T> |
28 struct EnableIf<true, T> { typedef T type; }; | 31 struct EnableIf<true, T> { typedef T type; }; |
29 | 32 |
30 // Types YesType and NoType are guaranteed such that sizeof(YesType) < | 33 // Types YesType and NoType are guaranteed such that sizeof(YesType) < |
31 // sizeof(NoType). | 34 // sizeof(NoType). |
32 typedef char YesType; | 35 typedef char YesType; |
33 | 36 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 | 79 |
77 static Derived* CreateDerived(); | 80 static Derived* CreateDerived(); |
78 static char (&Check(Base*))[1]; | 81 static char (&Check(Base*))[1]; |
79 static char (&Check(...))[2]; | 82 static char (&Check(...))[2]; |
80 | 83 |
81 public: | 84 public: |
82 static bool const value = sizeof Check(CreateDerived()) == 1 && | 85 static bool const value = sizeof Check(CreateDerived()) == 1 && |
83 !IsSame<Base const, void const>::value; | 86 !IsSame<Base const, void const>::value; |
84 }; | 87 }; |
85 | 88 |
89 template<class T> struct RemovePointer{}; | |
viettrungluu
2014/10/06 23:08:40
nit: space before "{}"
qsr
2014/10/07 08:56:12
Done.
| |
90 template<class T> struct RemovePointer<T*> { typedef T type; }; | |
91 | |
86 } // namespace internal | 92 } // namespace internal |
87 } // namespace mojo | 93 } // namespace mojo |
88 | 94 |
89 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ | 95 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_TEMPLATE_UTIL_H_ |
OLD | NEW |