Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #ifndef _ACCUMULATABLE_H
  2. #define _ACCUMULATABLE_H
  3.  
  4. #include <vector>
  5. #include <string>
  6.  
  7. //!A simple class for std::vector<std::string> accumulating functionality
  8. /*!
  9.     Constructors are inherited from std::vector
  10. */
  11. class accumulatable : public std::vector<std::string>
  12. {
  13. public:
  14.     accumulatable() = default;
  15.     accumulatable(const std::initializer_list<std::string>& init)
  16.         : std::vector<std::string>(init)
  17.     { }
  18.  
  19.  
  20.     /*!
  21.         \param del the delimeter to be used when accumulating, default is an empty string
  22.         \brief accumulates the contents of this container by the given delimeter
  23.     */
  24.     std::string acc(const std::string& del = "")
  25.     {
  26.         std::string r = "";
  27.         for (auto it = this->begin(); it != this->end() - 1; ++it)
  28.             r += *it + del;
  29.  
  30.         return r + this->at(this->size() - 1);
  31.     }
  32. };
  33.  
  34. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement