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

Unified Diff: webrtc/base/safe_conversions.h

Issue 2714063002: Introduce dchecked_cast, and start using it (Closed)
Patch Set: Created 3 years, 10 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: webrtc/base/safe_conversions.h
diff --git a/webrtc/base/safe_conversions.h b/webrtc/base/safe_conversions.h
index 51239bc65dd33ceec4bf68ce7ce8d662dbaa13c9..ff9cc44bc2c183ecb831acdc01fbc2ef1e7f4d66 100644
--- a/webrtc/base/safe_conversions.h
+++ b/webrtc/base/safe_conversions.h
@@ -27,14 +27,20 @@ inline bool IsValueInRangeForNumericType(Src value) {
return internal::RangeCheck<Dst>(value) == internal::TYPE_VALID;
}
-// checked_cast<> is analogous to static_cast<> for numeric types,
-// except that it CHECKs that the specified numeric conversion will not
-// overflow or underflow. NaN source will always trigger a CHECK.
+// checked_cast<> and dchecked_cast<> are analogous to static_cast<> for
+// numeric types, except that they [D]CHECK that the specified numeric
+// conversion will not overflow or underflow. NaN source will always trigger
+// the [D]CHECK.
template <typename Dst, typename Src>
inline Dst checked_cast(Src value) {
RTC_CHECK(IsValueInRangeForNumericType<Dst>(value));
return static_cast<Dst>(value);
}
+template <typename Dst, typename Src>
+inline Dst dchecked_cast(Src value) {
+ RTC_DCHECK(IsValueInRangeForNumericType<Dst>(value));
+ return static_cast<Dst>(value);
+}
// saturated_cast<> is analogous to static_cast<> for numeric types, except
// that the specified numeric conversion will saturate rather than overflow or
« no previous file with comments | « no previous file | webrtc/modules/audio_coding/acm2/acm_receiver.cc » ('j') | webrtc/modules/audio_coding/neteq/neteq_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698