Gabriel B. has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/71840?usp=email )

Change subject: base: Add Printer util class to force use of operator<< helpers
......................................................................

base: Add Printer util class to force use of operator<< helpers

Wrapping any value in a Printer instance before using operator<< will
force the use of stl_helpers::operator<<.

Change-Id: I7b505194eeabc3e0721effd9b5ce98f9e151b807
---
M src/base/stl_helpers/ostream_helpers.hh
1 file changed, 22 insertions(+), 1 deletion(-)



diff --git a/src/base/stl_helpers/ostream_helpers.hh b/src/base/stl_helpers/ostream_helpers.hh
index cee5fc0..d562a4d 100644
--- a/src/base/stl_helpers/ostream_helpers.hh
+++ b/src/base/stl_helpers/ostream_helpers.hh
@@ -41,6 +41,19 @@
 namespace gem5::stl_helpers
 {

+/*
+ * Wrap any object in a Printer object to force using a opExtract_impl printing
+ * function. This is not required for types that do not already enable
+ * operator<< in another namespace. However, to enable the special printing
+ * function for, e.g., raw pointers, those must be wrapped in a Printer.
+ */
+template<typename T>
+struct Printer
+{
+    Printer(const T& value): value{value} {}
+    const T& value;
+};
+
 namespace opExtract_impl
 {

@@ -128,6 +141,13 @@
     return opExtractPrimDisp(os, p.get());
 }

+template <typename T>
+std::ostream&
+opExtractPrimDisp(std::ostream& os, const Printer<T>& p)
+{
+    return opExtractSecDisp(os, p.value);
+}
+
 template <typename, typename = void>
 constexpr bool isOpExtractNativelySupported = false;

@@ -179,7 +199,8 @@

 } // namespace opExtract_impl

-// Add "using stl_helpers::operator<<" in the scope where you want to use it. +// use the Printer wrapper or add "using stl_helpers::operator<<" in the scope
+// where you want to use that operator<<.
 template<typename T>
 std::enable_if_t<opExtract_impl::needsDispatch<T>, std::ostream&>
 operator<<(std::ostream& os, const T& v)

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/71840?usp=email To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I7b505194eeabc3e0721effd9b5ce98f9e151b807
Gerrit-Change-Number: 71840
Gerrit-PatchSet: 1
Gerrit-Owner: Gabriel B. <gabriel.bus...@arteris.com>
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org

Reply via email to