Skip to content

Commit

Permalink
Utility to convert container to whitespace-separated string
Browse files Browse the repository at this point in the history
In support of libqueso#569
  • Loading branch information
briadam committed Oct 12, 2017
1 parent 866c2f2 commit 0f6191a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/misc/inc/Miscellaneous.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ void MiscComputePositionsBetweenMinMax(V minValues, V maxValues,
template <class V1,class V2>
void MiscCheckTheParallelEnvironment(const V1& vec1, const V2& vec2);

//! Convert container contents to space-separated string, omitting trailing whitespace
template<typename T>
std::string container_to_string(const T& container);

} // End namespace QUESO

#endif // UQ_MISCELLANEOUS_H
16 changes: 16 additions & 0 deletions src/misc/src/Miscellaneous.C
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <sys/time.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <libgen.h>
#include <sys/stat.h>
#include <cmath>
Expand Down Expand Up @@ -595,8 +596,23 @@ MiscCheckTheParallelEnvironment(const V1& vec1, const V2& vec2)
return;
}


template<typename T>
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, QUESO::GslVector>(QUESO::GslVector const&, QUESO::GslVector const&);
template bool QUESO::MiscCheckForSameValueInAllNodes<bool>(bool&, double, QUESO::MpiComm const&, char const*);
template bool QUESO::MiscCheckForSameValueInAllNodes<double>(double&, double, QUESO::MpiComm const&, char const*);
template std::string QUESO::container_to_string(const std::set<unsigned int>& container);

0 comments on commit 0f6191a

Please sign in to comment.