OLD | NEW |
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 // | 66 // |
67 // All three functions allow callers to explicitly specify the return type as a | 67 // All three functions allow callers to explicitly specify the return type as a |
68 // template parameter, overriding the default return type. E.g. | 68 // template parameter, overriding the default return type. E.g. |
69 // | 69 // |
70 // rtc::SafeMin<int>(x, y) // returns an int | 70 // rtc::SafeMin<int>(x, y) // returns an int |
71 // | 71 // |
72 // If the requested type is statically guaranteed to be able to represent the | 72 // If the requested type is statically guaranteed to be able to represent the |
73 // result, then everything's fine, and the return type is as requested. But if | 73 // result, then everything's fine, and the return type is as requested. But if |
74 // the requested type is too small, a static_assert is triggered. | 74 // the requested type is too small, a static_assert is triggered. |
75 | 75 |
76 #ifndef WEBRTC_BASE_SAFE_MINMAX_H_ | 76 #ifndef WEBRTC_RTC_BASE_SAFE_MINMAX_H_ |
77 #define WEBRTC_BASE_SAFE_MINMAX_H_ | 77 #define WEBRTC_RTC_BASE_SAFE_MINMAX_H_ |
78 | 78 |
79 #include <limits> | 79 #include <limits> |
80 #include <type_traits> | 80 #include <type_traits> |
81 | 81 |
82 #include "webrtc/base/checks.h" | 82 #include "webrtc/base/checks.h" |
83 #include "webrtc/base/safe_compare.h" | 83 #include "webrtc/base/safe_compare.h" |
84 #include "webrtc/base/type_traits.h" | 84 #include "webrtc/base/type_traits.h" |
85 | 85 |
86 namespace rtc { | 86 namespace rtc { |
87 | 87 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 static_assert(IsIntlike<L>::value || std::is_floating_point<L>::value, | 325 static_assert(IsIntlike<L>::value || std::is_floating_point<L>::value, |
326 "The third argument must be integral or floating-point"); | 326 "The third argument must be integral or floating-point"); |
327 RTC_DCHECK_LE(min, max); | 327 RTC_DCHECK_LE(min, max); |
328 return SafeLe(x, min) | 328 return SafeLe(x, min) |
329 ? static_cast<R2>(min) | 329 ? static_cast<R2>(min) |
330 : SafeGe(x, max) ? static_cast<R2>(max) : static_cast<R2>(x); | 330 : SafeGe(x, max) ? static_cast<R2>(max) : static_cast<R2>(x); |
331 } | 331 } |
332 | 332 |
333 } // namespace rtc | 333 } // namespace rtc |
334 | 334 |
335 #endif // WEBRTC_BASE_SAFE_MINMAX_H_ | 335 #endif // WEBRTC_RTC_BASE_SAFE_MINMAX_H_ |
OLD | NEW |