[PATCH] Python-like join function for string lists
Shankar Kalpathi Easwaran
shankarke at gmail.com
Tue Sep 3 12:27:52 PDT 2013
================
Comment at: include/llvm/ADT/StringExtras.h:188-190
@@ +187,5 @@
+ size_t Len = 0;
+ for (iter I = Begin; I != End; ++I)
+ Len += (*Begin).size() + Separator.size();
+ Len -= Separator.size();
+ S.reserve(Len);
----------------
We can use std::distance here
================
Comment at: include/llvm/ADT/StringExtras.h:163-177
@@ -161,1 +162,17 @@
+template <typename iter>
+static inline std::string join_impl(iter Begin, iter End, StringRef Separator,
+ std::input_iterator_tag)
+{
+ std::string S;
+ if (Begin == End)
+ return S;
+
+ S += (*Begin);
+ while (++Begin != End) {
+ S += Separator;
+ S += (*Begin);
+ }
+ return S;
+}
+
----------------
why would anyone use this version over the other ?
================
Comment at: include/llvm/ADT/StringExtras.h:179-182
@@ +178,6 @@
+
+template <typename iter>
+static inline std::string join_impl(iter Begin, iter End, StringRef Separator,
+ std::forward_iterator_tag)
+{
+ std::string S;
----------------
Couldnt follow why a tag is needed here.
http://llvm-reviews.chandlerc.com/D1585
More information about the llvm-commits
mailing list