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

Side by Side Diff: base/template_util.h

Issue 2790403003: Remove base::is_*assignable as these are now in the linux sysroot. (Closed)
Patch Set: isassign: removed-tests Created 3 years, 8 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
« no previous file with comments | « base/bind_unittest.cc ('k') | base/template_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #if !defined(__clang__) && defined(_LIBCPP_VERSION) 44 #if !defined(__clang__) && defined(_LIBCPP_VERSION)
45 #define CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX 45 #define CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX
46 #endif 46 #endif
47 47
48 namespace base { 48 namespace base {
49 49
50 template <class T> struct is_non_const_reference : std::false_type {}; 50 template <class T> struct is_non_const_reference : std::false_type {};
51 template <class T> struct is_non_const_reference<T&> : std::true_type {}; 51 template <class T> struct is_non_const_reference<T&> : std::true_type {};
52 template <class T> struct is_non_const_reference<const T&> : std::false_type {}; 52 template <class T> struct is_non_const_reference<const T&> : std::false_type {};
53 53
54 // is_assignable
55
56 namespace internal { 54 namespace internal {
57 55
58 template <typename First, typename Second>
59 struct SelectSecond {
60 using type = Second;
61 };
62
63 struct Any {
64 Any(...);
65 };
66
67 // True case: If |Lvalue| can be assigned to from |Rvalue|, then the return
68 // value is a true_type.
69 template <class Lvalue, class Rvalue>
70 typename internal::SelectSecond<
71 decltype((std::declval<Lvalue>() = std::declval<Rvalue>())),
72 std::true_type>::type
73 IsAssignableTest(Lvalue&&, Rvalue&&);
74
75 // False case: Otherwise the return value is a false_type.
76 template <class Rvalue>
77 std::false_type IsAssignableTest(internal::Any, Rvalue&&);
78
79 // Default case: Neither Lvalue nor Rvalue is void. Uses IsAssignableTest to
80 // determine the type of IsAssignableImpl.
81 template <class Lvalue,
82 class Rvalue,
83 bool = std::is_void<Lvalue>::value || std::is_void<Rvalue>::value>
84 struct IsAssignableImpl
85 : public std::common_type<decltype(
86 internal::IsAssignableTest(std::declval<Lvalue>(),
87 std::declval<Rvalue>()))>::type {};
88
89 // Void case: Either Lvalue or Rvalue is void. Then the type of IsAssignableTest
90 // is false_type.
91 template <class Lvalue, class Rvalue>
92 struct IsAssignableImpl<Lvalue, Rvalue, true> : public std::false_type {};
93
94 // Uses expression SFINAE to detect whether using operator<< would work. 56 // Uses expression SFINAE to detect whether using operator<< would work.
95 template <typename T, typename = void> 57 template <typename T, typename = void>
96 struct SupportsOstreamOperator : std::false_type {}; 58 struct SupportsOstreamOperator : std::false_type {};
97 template <typename T> 59 template <typename T>
98 struct SupportsOstreamOperator<T, 60 struct SupportsOstreamOperator<T,
99 decltype(void(std::declval<std::ostream&>() 61 decltype(void(std::declval<std::ostream&>()
100 << std::declval<T>()))> 62 << std::declval<T>()))>
101 : std::true_type {}; 63 : std::true_type {};
102 64
103 } // namespace internal 65 } // namespace internal
104 66
105 // TODO(crbug.com/554293): Remove this when all platforms have this in the std
106 // namespace.
107 template <class Lvalue, class Rvalue>
108 struct is_assignable : public internal::IsAssignableImpl<Lvalue, Rvalue> {};
109
110 // is_copy_assignable is true if a T const& is assignable to a T&.
111 // TODO(crbug.com/554293): Remove this when all platforms have this in the std
112 // namespace.
113 template <class T>
114 struct is_copy_assignable
115 : public is_assignable<typename std::add_lvalue_reference<T>::type,
116 typename std::add_lvalue_reference<
117 typename std::add_const<T>::type>::type> {};
118
119 // is_move_assignable is true if a T&& is assignable to a T&.
120 // TODO(crbug.com/554293): Remove this when all platforms have this in the std
121 // namespace.
122 template <class T>
123 struct is_move_assignable
124 : public is_assignable<typename std::add_lvalue_reference<T>::type,
125 const typename std::add_rvalue_reference<T>::type> {
126 };
127
128 // underlying_type produces the integer type backing an enum type. 67 // underlying_type produces the integer type backing an enum type.
129 // TODO(crbug.com/554293): Remove this when all platforms have this in the std 68 // TODO(crbug.com/554293): Remove this when all platforms have this in the std
130 // namespace. 69 // namespace.
131 #if defined(CR_USE_FALLBACKS_FOR_OLD_GLIBCXX) 70 #if defined(CR_USE_FALLBACKS_FOR_OLD_GLIBCXX)
132 template <typename T> 71 template <typename T>
133 struct underlying_type { 72 struct underlying_type {
134 using type = __underlying_type(T); 73 using type = __underlying_type(T);
135 }; 74 };
136 #else 75 #else
137 template <typename T> 76 template <typename T>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 using is_trivially_copyable = std::is_trivially_copyable<T>; 130 using is_trivially_copyable = std::is_trivially_copyable<T>;
192 #endif 131 #endif
193 132
194 } // namespace base 133 } // namespace base
195 134
196 #undef CR_USE_FALLBACKS_FOR_OLD_GLIBCXX 135 #undef CR_USE_FALLBACKS_FOR_OLD_GLIBCXX
197 #undef CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX 136 #undef CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX
198 #undef CR_USE_FALLBACKS_FOR_OLD_EXPERIMENTAL_GLIBCXX 137 #undef CR_USE_FALLBACKS_FOR_OLD_EXPERIMENTAL_GLIBCXX
199 138
200 #endif // BASE_TEMPLATE_UTIL_H_ 139 #endif // BASE_TEMPLATE_UTIL_H_
OLDNEW
« no previous file with comments | « base/bind_unittest.cc ('k') | base/template_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698