blob: 601aa5d152eac798aa19b5abc4b78d2bff89e542 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2021 The Chromium Authors
Tom Sepez60c8cdf2021-11-22 21:01:102// 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 Kastingbaaa6ac02024-11-13 01:02:519#include <type_traits>
Tom Sepez60c8cdf2021-11-22 21:01:1010
11namespace base {
12namespace internal {
13
14template <typename T>
Peter Kastingbaaa6ac02024-11-13 01:02:5115 requires std::is_arithmetic_v<T>
Tom Sepez60c8cdf2021-11-22 21:01:1016class ClampedNumeric;
17template <typename T>
Peter Kastingbaaa6ac02024-11-13 01:02:5118 requires std::is_arithmetic_v<T>
Tom Sepez60c8cdf2021-11-22 21:01:1019class StrictNumeric;
20
21// Overload the ostream output operator to make logging work nicely.
22template <typename T>
23std::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.
29template <typename T>
30std::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_