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

Side by Side Diff: webrtc/base/safe_minmax.h

Issue 2916083003: SafeMin/SafeMax: Fix wrong return type when given two enum arguments (Closed)
Patch Set: Created 3 years, 6 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 | « no previous file | webrtc/base/safe_minmax_unittest.cc » ('j') | webrtc/base/safe_minmax_unittest.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2017 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2017 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 safe_cmp::Ge(Limits<type>::max, Limits<B>::max), 146 safe_cmp::Ge(Limits<type>::max, Limits<B>::max),
147 "The specified type isn't large enough"); 147 "The specified type isn't large enough");
148 static_assert(IsIntlike<type>::value == IsIntlike<B>::value && 148 static_assert(IsIntlike<type>::value == IsIntlike<B>::value &&
149 std::is_floating_point<type>::value == 149 std::is_floating_point<type>::value ==
150 std::is_floating_point<type>::value, 150 std::is_floating_point<type>::value,
151 "float<->int conversions not allowed"); 151 "float<->int conversions not allowed");
152 }; 152 };
153 153
154 } // namespace safe_minmax_impl 154 } // namespace safe_minmax_impl
155 155
156 template <typename R = safe_minmax_impl::DefaultType, 156 template <
157 typename T1 = safe_minmax_impl::DefaultType, 157 typename R = safe_minmax_impl::DefaultType,
158 typename T2 = safe_minmax_impl::DefaultType, 158 typename T1 = safe_minmax_impl::DefaultType,
159 typename R2 = typename safe_minmax_impl::TypeOr< 159 typename T2 = safe_minmax_impl::DefaultType,
160 R, 160 typename R2 = typename safe_minmax_impl::TypeOr<
161 typename safe_minmax_impl::UnderlyingType< 161 R,
162 typename safe_minmax_impl::MType<T1, T2>::min_t>::type>::type> 162 typename safe_minmax_impl::MType<
163 typename safe_minmax_impl::UnderlyingType<T1>::type,
164 typename safe_minmax_impl::UnderlyingType<T2>::type>::min_t>::type>
163 constexpr R2 SafeMin(T1 a, T2 b) { 165 constexpr R2 SafeMin(T1 a, T2 b) {
164 static_assert(IsIntlike<T1>::value || std::is_floating_point<T1>::value, 166 static_assert(IsIntlike<T1>::value || std::is_floating_point<T1>::value,
165 "The first argument must be integral or floating-point"); 167 "The first argument must be integral or floating-point");
166 static_assert(IsIntlike<T2>::value || std::is_floating_point<T2>::value, 168 static_assert(IsIntlike<T2>::value || std::is_floating_point<T2>::value,
167 "The second argument must be integral or floating-point"); 169 "The second argument must be integral or floating-point");
168 return safe_cmp::Lt(a, b) ? static_cast<R2>(a) : static_cast<R2>(b); 170 return safe_cmp::Lt(a, b) ? static_cast<R2>(a) : static_cast<R2>(b);
169 } 171 }
170 172
171 template <typename R = safe_minmax_impl::DefaultType, 173 template <
172 typename T1 = safe_minmax_impl::DefaultType, 174 typename R = safe_minmax_impl::DefaultType,
173 typename T2 = safe_minmax_impl::DefaultType, 175 typename T1 = safe_minmax_impl::DefaultType,
174 typename R2 = typename safe_minmax_impl::TypeOr< 176 typename T2 = safe_minmax_impl::DefaultType,
175 R, 177 typename R2 = typename safe_minmax_impl::TypeOr<
176 typename safe_minmax_impl::UnderlyingType< 178 R,
177 typename safe_minmax_impl::MType<T1, T2>::max_t>::type>::type> 179 typename safe_minmax_impl::MType<
180 typename safe_minmax_impl::UnderlyingType<T1>::type,
181 typename safe_minmax_impl::UnderlyingType<T2>::type>::max_t>::type>
178 constexpr R2 SafeMax(T1 a, T2 b) { 182 constexpr R2 SafeMax(T1 a, T2 b) {
179 static_assert(IsIntlike<T1>::value || std::is_floating_point<T1>::value, 183 static_assert(IsIntlike<T1>::value || std::is_floating_point<T1>::value,
180 "The first argument must be integral or floating-point"); 184 "The first argument must be integral or floating-point");
181 static_assert(IsIntlike<T2>::value || std::is_floating_point<T2>::value, 185 static_assert(IsIntlike<T2>::value || std::is_floating_point<T2>::value,
182 "The second argument must be integral or floating-point"); 186 "The second argument must be integral or floating-point");
183 return safe_cmp::Gt(a, b) ? static_cast<R2>(a) : static_cast<R2>(b); 187 return safe_cmp::Gt(a, b) ? static_cast<R2>(a) : static_cast<R2>(b);
184 } 188 }
185 189
186 } // namespace rtc 190 } // namespace rtc
187 191
188 #endif // WEBRTC_BASE_SAFE_MINMAX_H_ 192 #endif // WEBRTC_BASE_SAFE_MINMAX_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/safe_minmax_unittest.cc » ('j') | webrtc/base/safe_minmax_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698