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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: base/template_util.h
diff --git a/base/template_util.h b/base/template_util.h
index 74c8e5afdc63dfb63f25922fc62835d854a8d48b..98506f029dee2f22a31fba0d2999b8de33cd72d3 100644
--- a/base/template_util.h
+++ b/base/template_util.h
@@ -6,6 +6,7 @@
#define BASE_TEMPLATE_UTIL_H_
#include <stddef.h>
+#include <iosfwd>
#include <type_traits>
#include <utility>
@@ -57,6 +58,15 @@ struct IsAssignableImpl
template <class Lvalue, class Rvalue>
struct IsAssignableImpl<Lvalue, Rvalue, true> : public std::false_type {};
+// Uses expression SFINAE to detect whether using operator<< would work.
+template <typename T, typename = void>
+struct SupportsOstreamOperator : std::false_type {};
+template <typename T>
+struct SupportsOstreamOperator<T,
+ decltype(void(std::declval<std::ostream&>()
+ << std::declval<T>()))>
+ : std::true_type {};
+
} // namespace internal
// TODO(crbug.com/554293): Remove this when all platforms have this in the std
@@ -82,6 +92,26 @@ struct is_move_assignable
const typename std::add_rvalue_reference<T>::type> {
};
+// underlying_type produces the integer type backing an enum type.
+// This hacks around libstdc++ 4.6 missing std::underlying_type, while we need
+// to support it.
+// TODO(crbug.com/554293): Remove this when all platforms have this in the std
+// namespace.
+#define CR_GLIBCXX_4_7_0 20120322
+#define CR_GLIBCXX_4_5_4 20120702
+#define CR_GLIBCXX_4_6_4 20121127
+#if defined(__GLIBCXX__) && \
+ (__GLIBCXX__ < CR_GLIBCXX_4_7_0 || __GLIBCXX__ == CR_GLIBCXX_4_5_4 || \
+ __GLIBCXX__ == CR_GLIBCXX_4_6_4)
+template <typename T>
+struct underlying_type {
+ using type = __underlying_type(T);
+};
+#else
+template <typename T>
+using underlying_type = std::underlying_type<T>;
+#endif
+
} // namespace base
#endif // BASE_TEMPLATE_UTIL_H_
« 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