Fixed two major bugs in paxos.cc.
[invirt/third/libt4.git] / types.h
diff --git a/types.h b/types.h
index cdb629a..0897649 100644 (file)
--- a/types.h
+++ b/types.h
@@ -48,8 +48,6 @@ using std::setfill;
 using std::setprecision;
 using std::ostream;
 using std::istream;
-using std::ostream_iterator;
-using std::istream_iterator;
 using std::ios;
 
 #include <limits>
@@ -133,12 +131,13 @@ template<typename E> constexpr inline E to_enum(enum_type_t<E> value) noexcept {
 template <class C>
 inline typename enable_if<is_const_iterable<C>::value, string>::type
 implode(const C & v, string delim=" ") {
-    if (v.begin() == v.end())
+    auto i=v.cbegin(), end=v.cend();
+    if (i == end)
         return string();
     ostringstream oss;
-    auto last = prev(v.end());
-    copy(v.begin(), last, ostream_iterator<typename C::value_type>(oss, delim.c_str()));
-    oss << *last;
+    oss << *i++;
+    while (i != end)
+        oss << delim << *i++;
     return oss.str();
 }
 
@@ -147,7 +146,7 @@ inline vector<string> explode(const string &s, string delim=" ") {
     size_t start = 0, end = 0;
     while ((end = s.find(delim, start)) != string::npos) {
         out.push_back(s.substr(start, end - start));
-        start = end + 1;
+        start = end + delim.size();
     }
     out.push_back(s.substr(start));
     return out;