| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 BASE_TEMPLATE_UTIL_H_ | 5 #ifndef BASE_TEMPLATE_UTIL_H_ |
| 6 #define BASE_TEMPLATE_UTIL_H_ | 6 #define BASE_TEMPLATE_UTIL_H_ |
| 7 | 7 |
| 8 #include <cstddef> // For size_t. | 8 #include <cstddef> // For size_t. |
| 9 #include <type_traits> |
| 9 | 10 |
| 10 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 | 14 |
| 14 // template definitions from tr1 | 15 // template definitions from tr1 |
| 15 | 16 |
| 16 template<class T, T v> | 17 template<class T, T v> |
| 17 struct integral_constant { | 18 struct integral_constant { |
| 18 static const T value = v; | 19 static const T value = v; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 49 template <class T> struct is_non_const_reference : false_type {}; | 50 template <class T> struct is_non_const_reference : false_type {}; |
| 50 template <class T> struct is_non_const_reference<T&> : true_type {}; | 51 template <class T> struct is_non_const_reference<T&> : true_type {}; |
| 51 template <class T> struct is_non_const_reference<const T&> : false_type {}; | 52 template <class T> struct is_non_const_reference<const T&> : false_type {}; |
| 52 | 53 |
| 53 template <class T> struct is_const : false_type {}; | 54 template <class T> struct is_const : false_type {}; |
| 54 template <class T> struct is_const<const T> : true_type {}; | 55 template <class T> struct is_const<const T> : true_type {}; |
| 55 | 56 |
| 56 template <class T> struct is_void : false_type {}; | 57 template <class T> struct is_void : false_type {}; |
| 57 template <> struct is_void<void> : true_type {}; | 58 template <> struct is_void<void> : true_type {}; |
| 58 | 59 |
| 60 template <typename T> |
| 61 struct is_move_constructible : public std::is_constructible<T, T&&> {}; |
| 62 |
| 63 template <typename T> |
| 64 struct is_copy_constructible : public std::is_constructible<T, const T&> {}; |
| 65 |
| 66 template <typename T> |
| 67 struct is_move_only |
| 68 : public std::conditional<!is_copy_constructible<T>::value, |
| 69 typename is_move_constructible<T>::type, |
| 70 std::false_type>::type {}; |
| 71 |
| 59 namespace internal { | 72 namespace internal { |
| 60 | 73 |
| 61 // Types YesType and NoType are guaranteed such that sizeof(YesType) < | 74 // Types YesType and NoType are guaranteed such that sizeof(YesType) < |
| 62 // sizeof(NoType). | 75 // sizeof(NoType). |
| 63 typedef char YesType; | 76 typedef char YesType; |
| 64 | 77 |
| 65 struct NoType { | 78 struct NoType { |
| 66 YesType dummy[2]; | 79 YesType dummy[2]; |
| 67 }; | 80 }; |
| 68 | 81 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 132 |
| 120 template<bool B, class T = void> | 133 template<bool B, class T = void> |
| 121 struct enable_if {}; | 134 struct enable_if {}; |
| 122 | 135 |
| 123 template<class T> | 136 template<class T> |
| 124 struct enable_if<true, T> { typedef T type; }; | 137 struct enable_if<true, T> { typedef T type; }; |
| 125 | 138 |
| 126 } // namespace base | 139 } // namespace base |
| 127 | 140 |
| 128 #endif // BASE_TEMPLATE_UTIL_H_ | 141 #endif // BASE_TEMPLATE_UTIL_H_ |
| OLD | NEW |