From 5a9eeba05f991e866c986a0bb1eaed912c083c91 Mon Sep 17 00:00:00 2001 From: "Brian M. Adams" Date: Tue, 3 Oct 2017 14:15:39 -0600 Subject: [PATCH] Utility to convert container to whitespace-separated string In support of libqueso/queso#569 --- src/misc/inc/Miscellaneous.h | 4 ++++ src/misc/src/Miscellaneous.C | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/misc/inc/Miscellaneous.h b/src/misc/inc/Miscellaneous.h index 094db1a46..602631b79 100644 --- a/src/misc/inc/Miscellaneous.h +++ b/src/misc/inc/Miscellaneous.h @@ -80,6 +80,10 @@ void MiscComputePositionsBetweenMinMax(V minValues, V maxValues, template void MiscCheckTheParallelEnvironment(const V1& vec1, const V2& vec2); +//! Convert container contents to space-separated string, omitting trailing whitespace +template +std::string container_to_string(const T& container); + } // End namespace QUESO #endif // UQ_MISCELLANEOUS_H diff --git a/src/misc/src/Miscellaneous.C b/src/misc/src/Miscellaneous.C index a8a00592c..6591ce6f4 100644 --- a/src/misc/src/Miscellaneous.C +++ b/src/misc/src/Miscellaneous.C @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -595,8 +596,23 @@ MiscCheckTheParallelEnvironment(const V1& vec1, const V2& vec2) return; } + +template +std::string container_to_string(const T& container) +{ + std::ostringstream oss; + typename T::const_iterator it = container.begin(); + for ( ; it != container.end(); ++it) { + if (it != container.begin()) + oss << ' '; + oss << *it; + } + return oss.str(); +} + } // End namespace QUESO template void QUESO::MiscCheckTheParallelEnvironment(QUESO::GslVector const&, QUESO::GslVector const&); template bool QUESO::MiscCheckForSameValueInAllNodes(bool&, double, QUESO::MpiComm const&, char const*); template bool QUESO::MiscCheckForSameValueInAllNodes(double&, double, QUESO::MpiComm const&, char const*); +template std::string QUESO::container_to_string(const std::set& container);