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

Side by Side Diff: util/numeric/checked_range.h

Issue 700383007: Use implicit_cast<> instead of static_cast<> whenever possible (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 //! \return `true` if the range is valid, `false` otherwise. 56 //! \return `true` if the range is valid, `false` otherwise.
57 //! 57 //!
58 //! A range is valid if its size can be converted to the range’s data type 58 //! A range is valid if its size can be converted to the range’s data type
59 //! without data loss, and if its end (base plus size) can be computed without 59 //! without data loss, and if its end (base plus size) can be computed without
60 //! overflowing its data type. 60 //! overflowing its data type.
61 bool IsValid() const { 61 bool IsValid() const {
62 if (!base::IsValueInRangeForNumericType<ValueType, SizeType>(size_)) { 62 if (!base::IsValueInRangeForNumericType<ValueType, SizeType>(size_)) {
63 return false; 63 return false;
64 } 64 }
65 base::CheckedNumeric<ValueType> checked_end(base_); 65 base::CheckedNumeric<ValueType> checked_end(base_);
66 checked_end += static_cast<ValueType>(size_); 66 checked_end += implicit_cast<ValueType>(size_);
67 return checked_end.IsValid(); 67 return checked_end.IsValid();
68 } 68 }
69 69
70 //! \brief Returns whether the range contains another value. 70 //! \brief Returns whether the range contains another value.
71 //! 71 //!
72 //! \param[in] value The (possibly) contained value. 72 //! \param[in] value The (possibly) contained value.
73 //! 73 //!
74 //! \return `true` if the range contains \a value, `false` otherwise. 74 //! \return `true` if the range contains \a value, `false` otherwise.
75 //! 75 //!
76 //! A range contains a value if the value is greater than or equal to its 76 //! A range contains a value if the value is greater than or equal to its
(...skipping 29 matching lines...) Expand all
106 private: 106 private:
107 ValueType base_; 107 ValueType base_;
108 SizeType size_; 108 SizeType size_;
109 109
110 DISALLOW_COPY_AND_ASSIGN(CheckedRange); 110 DISALLOW_COPY_AND_ASSIGN(CheckedRange);
111 }; 111 };
112 112
113 } // namespace crashpad 113 } // namespace crashpad
114 114
115 #endif // CRASHPAD_UTIL_NUMERIC_CHECKED_RANGE_H_ 115 #endif // CRASHPAD_UTIL_NUMERIC_CHECKED_RANGE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698