From ed0a56c185722b979b7667b635bacf9ae2b58052 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Sun, 23 May 2021 00:56:45 -0700 Subject: [PATCH] base: Apply the stl_helpers helper judiciously. The existing template would apply the helper operator to *any* template which took two types, regardless of what that template was. The assumption was that those types *must* be STL containers, because no other template takes two types, right? Instead, this new version uses type traits to explicitly whitelist types which the helper applies to. Currently the only type it seems to be used with is std::vector, but by defining more specializations of IsHelpedContainer, other types/templates can be enabled as well. This is particularly important when moving to c++17, since the std::string class would then apparently match the old overload. That makes the << operator ambiguous and breaks the build. Change-Id: Id283746a2ccced8882fa23e6f9e69fe22e206b70 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/45901 Reviewed-by: Gabe Black Reviewed-by: Daniel Carvalho Maintainer: Gabe Black Tested-by: kokoro --- src/base/stl_helpers.hh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/base/stl_helpers.hh b/src/base/stl_helpers.hh index 51dc0390e3..ba812b92df 100644 --- a/src/base/stl_helpers.hh +++ b/src/base/stl_helpers.hh @@ -31,29 +31,38 @@ #include #include +#include +#include namespace m5 { namespace stl_helpers { +template +struct IsHelpedContainer : public std::false_type {}; + +template +struct IsHelpedContainer> : public std::true_type {}; + /** * Write out all elements in an stl container as a space separated * list enclosed in square brackets * * @ingroup api_base_utils */ -template