Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: base/template_util.h

Issue 2001783002: base: Support using (D)CHECK on scoped enums. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use CR_GLIBCXX_4_7_0 macro, since I bothered to define it Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <type_traits> 10 #include <type_traits>
10 #include <utility> 11 #include <utility>
11 12
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 14
14 namespace base { 15 namespace base {
15 16
16 template <class T> struct is_non_const_reference : std::false_type {}; 17 template <class T> struct is_non_const_reference : std::false_type {};
17 template <class T> struct is_non_const_reference<T&> : std::true_type {}; 18 template <class T> struct is_non_const_reference<T&> : std::true_type {};
18 template <class T> struct is_non_const_reference<const T&> : std::false_type {}; 19 template <class T> struct is_non_const_reference<const T&> : std::false_type {};
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 struct IsAssignableImpl 51 struct IsAssignableImpl
51 : public std::common_type<decltype( 52 : public std::common_type<decltype(
52 internal::IsAssignableTest(std::declval<Lvalue>(), 53 internal::IsAssignableTest(std::declval<Lvalue>(),
53 std::declval<Rvalue>()))>::type {}; 54 std::declval<Rvalue>()))>::type {};
54 55
55 // Void case: Either Lvalue or Rvalue is void. Then the type of IsAssignableTest 56 // Void case: Either Lvalue or Rvalue is void. Then the type of IsAssignableTest
56 // is false_type. 57 // is false_type.
57 template <class Lvalue, class Rvalue> 58 template <class Lvalue, class Rvalue>
58 struct IsAssignableImpl<Lvalue, Rvalue, true> : public std::false_type {}; 59 struct IsAssignableImpl<Lvalue, Rvalue, true> : public std::false_type {};
59 60
61 // Uses expression SFINAE to detect whether using operator<< would work.
62 template <typename T, typename = void>
63 struct SupportsOstreamOperator : std::false_type {};
64 template <typename T>
65 struct SupportsOstreamOperator<T,
66 decltype(void(std::declval<std::ostream&>()
67 << std::declval<T>()))>
68 : std::true_type {};
69
60 } // namespace internal 70 } // namespace internal
61 71
62 // TODO(crbug.com/554293): Remove this when all platforms have this in the std 72 // TODO(crbug.com/554293): Remove this when all platforms have this in the std
63 // namespace. 73 // namespace.
64 template <class Lvalue, class Rvalue> 74 template <class Lvalue, class Rvalue>
65 struct is_assignable : public internal::IsAssignableImpl<Lvalue, Rvalue> {}; 75 struct is_assignable : public internal::IsAssignableImpl<Lvalue, Rvalue> {};
66 76
67 // is_copy_assignable is true if a T const& is assignable to a T&. 77 // is_copy_assignable is true if a T const& is assignable to a T&.
68 // TODO(crbug.com/554293): Remove this when all platforms have this in the std 78 // TODO(crbug.com/554293): Remove this when all platforms have this in the std
69 // namespace. 79 // namespace.
70 template <class T> 80 template <class T>
71 struct is_copy_assignable 81 struct is_copy_assignable
72 : public is_assignable<typename std::add_lvalue_reference<T>::type, 82 : public is_assignable<typename std::add_lvalue_reference<T>::type,
73 typename std::add_lvalue_reference< 83 typename std::add_lvalue_reference<
74 typename std::add_const<T>::type>::type> {}; 84 typename std::add_const<T>::type>::type> {};
75 85
76 // is_move_assignable is true if a T&& is assignable to a T&. 86 // is_move_assignable is true if a T&& is assignable to a T&.
77 // TODO(crbug.com/554293): Remove this when all platforms have this in the std 87 // TODO(crbug.com/554293): Remove this when all platforms have this in the std
78 // namespace. 88 // namespace.
79 template <class T> 89 template <class T>
80 struct is_move_assignable 90 struct is_move_assignable
81 : public is_assignable<typename std::add_lvalue_reference<T>::type, 91 : public is_assignable<typename std::add_lvalue_reference<T>::type,
82 const typename std::add_rvalue_reference<T>::type> { 92 const typename std::add_rvalue_reference<T>::type> {
83 }; 93 };
84 94
95 // 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
99 // namespace.
100 #define CR_GLIBCXX_4_7_0 20120322
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>
107 struct underlying_type {
108 using type = __underlying_type(T);
109 };
110 #else
111 template <typename T>
112 using underlying_type = std::underlying_type<T>;
113 #endif
114
85 } // namespace base 115 } // namespace base
86 116
87 #endif // BASE_TEMPLATE_UTIL_H_ 117 #endif // BASE_TEMPLATE_UTIL_H_
OLDNEW
« base/logging.h ('K') | « base/logging_unittest.cc ('k') | base/template_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698