summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2015-01-07 07:21:29 (GMT)
committerStephen Kelly <steveire@gmail.com>2015-01-08 21:28:18 (GMT)
commit8dc8d756bc278cd02f329b31218c2459908dc0bb (patch)
treefc6cad87f55ecfc7248afb9e62a3a347f99a50a0 /Source
parentb5813ceeb5b5f78351dd9f9c6af904db2f4451c9 (diff)
downloadCMake-8dc8d756bc278cd02f329b31218c2459908dc0bb.zip
CMake-8dc8d756bc278cd02f329b31218c2459908dc0bb.tar.gz
CMake-8dc8d756bc278cd02f329b31218c2459908dc0bb.tar.bz2
cmStandardIncludes: Add a join algorithm for string containers.
This requires the input range to supply BidirectionalIterators, which is not a problem for where it is currently useful to us. The alternative would be to not invoke --last;, and instead create an output iterator similar to std::ostream_iterator, but which puts the delimiter before the item to output.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmStandardIncludes.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/Source/cmStandardIncludes.h b/Source/cmStandardIncludes.h
index e4f5760..d7c6a65 100644
--- a/Source/cmStandardIncludes.h
+++ b/Source/cmStandardIncludes.h
@@ -358,6 +358,33 @@ static thisClass* SafeDownCast(cmObject *c) \
} \
class cmTypeMacro_UseTrailingSemicolon
+template<typename Range>
+std::string cmJoin(Range const& r, const char* delimiter)
+{
+ if (r.empty())
+ {
+ return std::string();
+ }
+ std::ostringstream os;
+ typedef typename Range::value_type ValueType;
+ typedef typename Range::const_iterator InputIt;
+ InputIt first = r.begin();
+ InputIt last = r.end();
+ --last;
+ std::copy(first, last,
+ std::ostream_iterator<ValueType>(os, delimiter));
+
+ os << *last;
+
+ return os.str();
+}
+
+template<typename Range>
+std::string cmJoin(Range const& r, std::string delimiter)
+{
+ return cmJoin(r, delimiter.c_str());
+};
+
inline bool cmHasLiteralPrefixImpl(const std::string &str1,
const char *str2,
size_t N)