Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Tom Sepez | 60c8cdf | 2021-11-22 21:01:10 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_NUMERICS_OSTREAM_OPERATORS_H_ |
| 6 | #define BASE_NUMERICS_OSTREAM_OPERATORS_H_ |
| 7 | |
| 8 | #include <ostream> |
Peter Kasting | baaa6ac0 | 2024-11-13 01:02:51 | [diff] [blame] | 9 | #include <type_traits> |
Tom Sepez | 60c8cdf | 2021-11-22 21:01:10 | [diff] [blame] | 10 | |
| 11 | namespace base { |
| 12 | namespace internal { |
| 13 | |
| 14 | template <typename T> |
Peter Kasting | baaa6ac0 | 2024-11-13 01:02:51 | [diff] [blame] | 15 | requires std::is_arithmetic_v<T> |
Tom Sepez | 60c8cdf | 2021-11-22 21:01:10 | [diff] [blame] | 16 | class ClampedNumeric; |
| 17 | template <typename T> |
Peter Kasting | baaa6ac0 | 2024-11-13 01:02:51 | [diff] [blame] | 18 | requires std::is_arithmetic_v<T> |
Tom Sepez | 60c8cdf | 2021-11-22 21:01:10 | [diff] [blame] | 19 | class StrictNumeric; |
| 20 | |
| 21 | // Overload the ostream output operator to make logging work nicely. |
| 22 | template <typename T> |
| 23 | std::ostream& operator<<(std::ostream& os, const StrictNumeric<T>& value) { |
| 24 | os << static_cast<T>(value); |
| 25 | return os; |
| 26 | } |
| 27 | |
| 28 | // Overload the ostream output operator to make logging work nicely. |
| 29 | template <typename T> |
| 30 | std::ostream& operator<<(std::ostream& os, const ClampedNumeric<T>& value) { |
| 31 | os << static_cast<T>(value); |
| 32 | return os; |
| 33 | } |
| 34 | |
| 35 | } // namespace internal |
| 36 | } // namespace base |
| 37 | |
| 38 | #endif // BASE_NUMERICS_OSTREAM_OPERATORS_H_ |