Gabe Black has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/45900 )
Change subject: base: Use a lambda to simplify the stl_helpers template.
......................................................................
base: Use a lambda to simplify the stl_helpers template.
Use a lambda to power the std::for_each instead of a functor class. This
takes *much* less code to implement.
Change-Id: Icc5d5a943630e7e19cd2e0fa6f2cef2c9b766e24
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/45900
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/base/stl_helpers.hh
1 file changed, 8 insertions(+), 32 deletions(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/base/stl_helpers.hh b/src/base/stl_helpers.hh
index ae369b5..51dc039 100644
--- a/src/base/stl_helpers.hh
+++ b/src/base/stl_helpers.hh
@@ -35,37 +35,6 @@
namespace m5 {
namespace stl_helpers {
-template <class T>
-class ContainerPrint
-{
- private:
- std::ostream &out;
- bool first;
-
- public:
- /**
- * @ingroup api_base_utils
- */
- ContainerPrint(std::ostream &out)
- : out(out), first(true)
- {}
-
- /**
- * @ingroup api_base_utils
- */
- void
- operator()(const T &elem)
- {
- // First one doesn't get a space before it. The rest do.
- if (first)
- first = false;
- else
- out << " ";
-
- out << elem;
- }
-};
-
/**
* Write out all elements in an stl container as a space separated
* list enclosed in square brackets
@@ -77,7 +46,14 @@
operator<<(std::ostream& out, const C<T,A> &vec)
{
out << "[ ";
- std::for_each(vec.begin(), vec.end(), ContainerPrint<T>(out));
+ bool first = true;
+ auto printer = [&first, &out](const T &elem) {
+ if (first)
+ out << elem;
+ else
+ out << " " << elem;
+ };
+ std::for_each(vec.begin(), vec.end(), printer);
out << " ]";
out << std::flush;
return out;
1 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the
submitted one.
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/45900
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Icc5d5a943630e7e19cd2e0fa6f2cef2c9b766e24
Gerrit-Change-Number: 45900
Gerrit-PatchSet: 3
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s