• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Chromium Authors
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>
9 #include <type_traits>
10 
11 namespace base {
12 namespace internal {
13 
14 template <typename T>
15   requires std::is_arithmetic_v<T>
16 class ClampedNumeric;
17 template <typename T>
18   requires std::is_arithmetic_v<T>
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_
39