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

Side by Side 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 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 <iosfwd>
10 #include <type_traits> 10 #include <type_traits>
(...skipping 11 matching lines...) Expand all
22 __GLIBCXX__ == CR_GLIBCXX_4_6_4) 22 __GLIBCXX__ == CR_GLIBCXX_4_6_4)
23 #define CR_USE_FALLBACKS_FOR_OLD_GLIBCXX 23 #define CR_USE_FALLBACKS_FOR_OLD_GLIBCXX
24 #endif 24 #endif
25 25
26 namespace base { 26 namespace base {
27 27
28 template <class T> struct is_non_const_reference : std::false_type {}; 28 template <class T> struct is_non_const_reference : std::false_type {};
29 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 {};
30 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 {};
31 31
32 // underlying_number
33 // Casts an enum to its underlying integral type, leaves other numbers alone.
34 // Useful for scoped enums, which don't cast implicitly.
35 template <typename T,
36 typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
37 constexpr typename std::underlying_type<T>::type underlying_number(T val) {
38 return static_cast<typename std::underlying_type<T>::type>(val);
39 }
40 template <typename T,
41 typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>
42 constexpr T underlying_number(T val) {
43 return val;
44 }
45
32 // is_assignable 46 // is_assignable
33 47
34 namespace internal { 48 namespace internal {
35 49
36 template <typename First, typename Second> 50 template <typename First, typename Second>
37 struct SelectSecond { 51 struct SelectSecond {
38 using type = Second; 52 using type = Second;
39 }; 53 };
40 54
41 struct Any { 55 struct Any {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 #else 138 #else
125 template <class T> 139 template <class T>
126 using is_trivially_destructible = std::is_trivially_destructible<T>; 140 using is_trivially_destructible = std::is_trivially_destructible<T>;
127 #endif 141 #endif
128 142
129 } // namespace base 143 } // namespace base
130 144
131 #undef CR_USE_FALLBACKS_FOR_OLD_GLIBCXX 145 #undef CR_USE_FALLBACKS_FOR_OLD_GLIBCXX
132 146
133 #endif // BASE_TEMPLATE_UTIL_H_ 147 #endif // BASE_TEMPLATE_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698