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

Side by Side Diff: base/safe_numerics.h

Issue 12051089: fix checked_numeric_cast comments (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/safe_numerics_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_SAFE_NUMERICS_H_ 5 #ifndef BASE_SAFE_NUMERICS_H_
6 #define BASE_SAFE_NUMERICS_H_ 6 #define BASE_SAFE_NUMERICS_H_
7 7
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 (sizeof(Dest) > sizeof(Source)), 113 (sizeof(Dest) > sizeof(Source)),
114 DestLimits::is_signed, 114 DestLimits::is_signed,
115 SourceLimits::is_signed>::Test( 115 SourceLimits::is_signed>::Test(
116 source, 116 source,
117 DestLimits::min(), 117 DestLimits::min(),
118 DestLimits::max()); 118 DestLimits::max());
119 } 119 }
120 120
121 } // namespace internal 121 } // namespace internal
122 122
123 // numeric_cast<> is analogous to static_cast<> for numeric types, except that 123 // checked_numeric_cast<> is analogous to static_cast<> for numeric types,
124 // it CHECKs that the specified numeric conversion will not overflow or 124 // except that it CHECKs that the specified numeric conversion will not
125 // underflow. Floating point arguments are not currently allowed (this is 125 // overflow or underflow. Floating point arguments are not currently allowed
126 // COMPILE_ASSERTd), though this could be supported if necessary. 126 // (this is COMPILE_ASSERTd), though this could be supported if necessary.
127 template <class Dest, class Source> 127 template <class Dest, class Source>
128 inline Dest checked_numeric_cast(Source source) { 128 inline Dest checked_numeric_cast(Source source) {
129 CHECK(internal::IsValidNumericCast<Dest>(source)); 129 CHECK(internal::IsValidNumericCast<Dest>(source));
130 return static_cast<Dest>(source); 130 return static_cast<Dest>(source);
131 } 131 }
132 132
133 } // namespace base 133 } // namespace base
134 134
135 #endif // BASE_SAFE_NUMERICS_H_ 135 #endif // BASE_SAFE_NUMERICS_H_
OLDNEW
« no previous file with comments | « no previous file | base/safe_numerics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698