Advertisement
Vultraz

Untitled

Sep 1st, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. BEFORE
  2. ==================================
  3. template <typename T>
  4. std::string join(T const &v, const std::string& s = ",")
  5. {
  6.         std::stringstream str;
  7.         for(typename T::const_iterator i = v.begin(); i != v.end(); ++i) {
  8.                 str << *i;
  9.                 if (std::next(i) != v.end())
  10.                         str << s;
  11.         }
  12.  
  13.         return str.str();
  14. }
  15.  
  16. AFTER
  17. ==================================
  18. template <typename T>
  19. std::string join(T const &v, const std::string& s = ",")
  20. {
  21.     using move_iter = std::move_iterator<typename T::const_iterator>;
  22.  
  23.     return std::accumulate(move_iter(v.begin()), move_iter(v.end()), s);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement