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

Unified Diff: base/template_util.h

Issue 2261793002: Bring the feedback button to the Mac sad tab (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Make a cast which only takes enums and numbers, fix nits Created 4 years, 4 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 1bfc1ac814a23ceb186a9fcf6fa5924281d92783..af4cdd5a21c4993dca662b7c717dfcc25b7f1714 100644
--- a/base/template_util.h
+++ b/base/template_util.h
@@ -29,6 +29,20 @@ template <class T> struct is_non_const_reference : std::false_type {};
template <class T> struct is_non_const_reference<T&> : std::true_type {};
template <class T> struct is_non_const_reference<const T&> : std::false_type {};
+// underlying_number
+// Casts an enum to its underlying integral type, leaves other numbers alone.
+// Useful for scoped enums, which don't cast implicitly.
+template <typename T,
+ typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
+constexpr typename std::underlying_type<T>::type underlying_number(T val) {
+ return static_cast<typename std::underlying_type<T>::type>(val);
+}
+template <typename T,
+ typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>
+constexpr T underlying_number(T val) {
+ return val;
+}
+
// is_assignable
namespace internal {

Powered by Google App Engine
This is Rietveld 408576698