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 <stddef.h> | 8 #include <stddef.h> |
9 #include <iosfwd> | 9 #include <iosfwd> |
10 #include <type_traits> | 10 #include <type_traits> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 | 14 |
| 15 // This hacks around libstdc++ 4.6 missing stuff in type_traits, while we need |
| 16 // to support it. |
| 17 #define CR_GLIBCXX_4_7_0 20120322 |
| 18 #define CR_GLIBCXX_4_5_4 20120702 |
| 19 #define CR_GLIBCXX_4_6_4 20121127 |
| 20 #if defined(__GLIBCXX__) && \ |
| 21 (__GLIBCXX__ < CR_GLIBCXX_4_7_0 || __GLIBCXX__ == CR_GLIBCXX_4_5_4 || \ |
| 22 __GLIBCXX__ == CR_GLIBCXX_4_6_4) |
| 23 #define CR_USE_FALLBACKS_FOR_OLD_GLIBCXX |
| 24 #endif |
| 25 |
15 namespace base { | 26 namespace base { |
16 | 27 |
17 template <class T> struct is_non_const_reference : std::false_type {}; | 28 template <class T> struct is_non_const_reference : std::false_type {}; |
18 template <class T> struct is_non_const_reference<T&> : std::true_type {}; | 29 template <class T> struct is_non_const_reference<T&> : std::true_type {}; |
19 template <class T> struct is_non_const_reference<const T&> : std::false_type {}; | 30 template <class T> struct is_non_const_reference<const T&> : std::false_type {}; |
20 | 31 |
21 // is_assignable | 32 // is_assignable |
22 | 33 |
23 namespace internal { | 34 namespace internal { |
24 | 35 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // is_move_assignable is true if a T&& is assignable to a T&. | 97 // is_move_assignable is true if a T&& is assignable to a T&. |
87 // TODO(crbug.com/554293): Remove this when all platforms have this in the std | 98 // TODO(crbug.com/554293): Remove this when all platforms have this in the std |
88 // namespace. | 99 // namespace. |
89 template <class T> | 100 template <class T> |
90 struct is_move_assignable | 101 struct is_move_assignable |
91 : public is_assignable<typename std::add_lvalue_reference<T>::type, | 102 : public is_assignable<typename std::add_lvalue_reference<T>::type, |
92 const typename std::add_rvalue_reference<T>::type> { | 103 const typename std::add_rvalue_reference<T>::type> { |
93 }; | 104 }; |
94 | 105 |
95 // underlying_type produces the integer type backing an enum type. | 106 // underlying_type produces the integer type backing an enum type. |
96 // This hacks around libstdc++ 4.6 missing std::underlying_type, while we need | |
97 // to support it. | |
98 // TODO(crbug.com/554293): Remove this when all platforms have this in the std | 107 // TODO(crbug.com/554293): Remove this when all platforms have this in the std |
99 // namespace. | 108 // namespace. |
100 #define CR_GLIBCXX_4_7_0 20120322 | 109 #if defined(CR_USE_FALLBACKS_FOR_OLD_GLIBCXX) |
101 #define CR_GLIBCXX_4_5_4 20120702 | |
102 #define CR_GLIBCXX_4_6_4 20121127 | |
103 #if defined(__GLIBCXX__) && \ | |
104 (__GLIBCXX__ < CR_GLIBCXX_4_7_0 || __GLIBCXX__ == CR_GLIBCXX_4_5_4 || \ | |
105 __GLIBCXX__ == CR_GLIBCXX_4_6_4) | |
106 template <typename T> | 110 template <typename T> |
107 struct underlying_type { | 111 struct underlying_type { |
108 using type = __underlying_type(T); | 112 using type = __underlying_type(T); |
109 }; | 113 }; |
110 #else | 114 #else |
111 template <typename T> | 115 template <typename T> |
112 using underlying_type = std::underlying_type<T>; | 116 using underlying_type = std::underlying_type<T>; |
113 #endif | 117 #endif |
114 | 118 |
| 119 // TODO(crbug.com/554293): Remove this when all platforms have this in the std |
| 120 // namespace. |
| 121 #if defined(CR_USE_FALLBACKS_FOR_OLD_GLIBCXX) |
| 122 template <class T> |
| 123 using is_trivially_destructible = std::has_trivial_destructor<T>; |
| 124 #else |
| 125 template <class T> |
| 126 using is_trivially_destructible = std::is_trivially_destructible<T>; |
| 127 #endif |
| 128 |
115 } // namespace base | 129 } // namespace base |
116 | 130 |
| 131 #undef CR_USE_FALLBACKS_FOR_OLD_GLIBCXX |
| 132 |
117 #endif // BASE_TEMPLATE_UTIL_H_ | 133 #endif // BASE_TEMPLATE_UTIL_H_ |
OLD | NEW |