| 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> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 namespace base { | 37 namespace base { |
| 38 | 38 |
| 39 template <class T> struct is_non_const_reference : std::false_type {}; | 39 template <class T> struct is_non_const_reference : std::false_type {}; |
| 40 template <class T> struct is_non_const_reference<T&> : std::true_type {}; | 40 template <class T> struct is_non_const_reference<T&> : std::true_type {}; |
| 41 template <class T> struct is_non_const_reference<const T&> : std::false_type {}; | 41 template <class T> struct is_non_const_reference<const T&> : std::false_type {}; |
| 42 | 42 |
| 43 namespace internal { | 43 namespace internal { |
| 44 | 44 |
| 45 template <typename...> |
| 46 struct make_void { |
| 47 using type = void; |
| 48 }; |
| 49 |
| 50 // A clone of C++17 std::void_t. |
| 51 // Unlike the original version, we need |make_void| as a helper struct to avoid |
| 52 // a C++14 defect. |
| 53 // ref: http://en.cppreference.com/w/cpp/types/void_t |
| 54 // ref: http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1558 |
| 55 template <typename... Ts> |
| 56 using void_t = typename make_void<Ts...>::type; |
| 57 |
| 45 // Uses expression SFINAE to detect whether using operator<< would work. | 58 // Uses expression SFINAE to detect whether using operator<< would work. |
| 46 template <typename T, typename = void> | 59 template <typename T, typename = void> |
| 47 struct SupportsOstreamOperator : std::false_type {}; | 60 struct SupportsOstreamOperator : std::false_type {}; |
| 48 template <typename T> | 61 template <typename T> |
| 49 struct SupportsOstreamOperator<T, | 62 struct SupportsOstreamOperator<T, |
| 50 decltype(void(std::declval<std::ostream&>() | 63 decltype(void(std::declval<std::ostream&>() |
| 51 << std::declval<T>()))> | 64 << std::declval<T>()))> |
| 52 : std::true_type {}; | 65 : std::true_type {}; |
| 53 | 66 |
| 54 } // namespace internal | 67 } // namespace internal |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 #else | 102 #else |
| 90 static constexpr bool value = | 103 static constexpr bool value = |
| 91 __has_trivial_copy(T) && __has_trivial_destructor(T); | 104 __has_trivial_copy(T) && __has_trivial_destructor(T); |
| 92 #endif | 105 #endif |
| 93 }; | 106 }; |
| 94 #else | 107 #else |
| 95 template <class T> | 108 template <class T> |
| 96 using is_trivially_copyable = std::is_trivially_copyable<T>; | 109 using is_trivially_copyable = std::is_trivially_copyable<T>; |
| 97 #endif | 110 #endif |
| 98 | 111 |
| 112 // std::less<> from C++14. |
| 113 struct less { |
| 114 template <typename T, typename U> |
| 115 constexpr auto operator()(T&& lhs, U&& rhs) const |
| 116 -> decltype(std::forward<T>(lhs) < std::forward<U>(rhs)) { |
| 117 return std::forward<T>(lhs) < std::forward<U>(rhs); |
| 118 } |
| 119 |
| 120 // You can find more information about transparent comparisons here: |
| 121 // http://en.cppreference.com/w/cpp/utility/functional/less_void |
| 122 using is_transparent = int; |
| 123 }; |
| 124 |
| 99 } // namespace base | 125 } // namespace base |
| 100 | 126 |
| 101 #undef CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX | 127 #undef CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX |
| 102 #undef CR_USE_FALLBACKS_FOR_OLD_EXPERIMENTAL_GLIBCXX | 128 #undef CR_USE_FALLBACKS_FOR_OLD_EXPERIMENTAL_GLIBCXX |
| 103 | 129 |
| 104 #endif // BASE_TEMPLATE_UTIL_H_ | 130 #endif // BASE_TEMPLATE_UTIL_H_ |
| OLD | NEW |