[v1,3/3] libcamera: base: utils: Fix names of `operator<<` for `Duration`
diff mbox series

Message ID 20260115111630.1892890-3-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • [v1,1/3] libcamera: base: utils: Simplify `operator<<` for `Duration`
Related show

Commit Message

Barnabás Pőcze Jan. 15, 2026, 11:16 a.m. UTC
In order for ADL to find the function, it must be in the namespace of any of
its arguments. Previously, however, that was not the case, and it has only
really worked by accident and could be easily made to fail by introducing
other `operator<<` overloads.

For example, a user of this function in `libcamera::ipa` would no longer
compile after introducing an `operator<<` into the `libcamera::ipa`
namespace as that would essentially hide this overload, and without ADL
it would not be found.

So move the function into the `utils` namespace.

Fixes: 5055ca747c4c ("libcamera: utils: Add helper class for std::chrono::duration")
Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 include/libcamera/base/utils.h | 6 +++---
 src/libcamera/base/utils.cpp   | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
index 6ce1ace43..fc4f5079c 100644
--- a/include/libcamera/base/utils.h
+++ b/include/libcamera/base/utils.h
@@ -423,10 +423,10 @@  scope_exit(EF) -> scope_exit<EF>;
 
 #endif /* __DOXYGEN__ */
 
-} /* namespace utils */
-
 #ifndef __DOXYGEN__
-std::ostream &operator<<(std::ostream &os, const utils::Duration &d);
+std::ostream &operator<<(std::ostream &os, const Duration &d);
 #endif
 
+} /* namespace utils */
+
 } /* namespace libcamera */
diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp
index 2c3f2b7e6..42a516097 100644
--- a/src/libcamera/base/utils.cpp
+++ b/src/libcamera/base/utils.cpp
@@ -655,10 +655,8 @@  void ScopeExitActions::release()
 	actions_.clear();
 }
 
-} /* namespace utils */
-
 #ifndef __DOXYGEN__
-std::ostream &operator<<(std::ostream &os, const utils::Duration &d)
+std::ostream &operator<<(std::ostream &os, const Duration &d)
 {
 	std::ostringstream s;
 
@@ -671,4 +669,6 @@  std::ostream &operator<<(std::ostream &os, const utils::Duration &d)
 }
 #endif
 
+} /* namespace utils */
+
 } /* namespace libcamera */