Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _ACCUMULATABLE_H
- #define _ACCUMULATABLE_H
- #include <vector>
- #include <string>
- //!A simple class for std::vector<std::string> accumulating functionality
- /*!
- Constructors are inherited from std::vector
- */
- class accumulatable : public std::vector<std::string>
- {
- public:
- accumulatable() = default;
- accumulatable(const std::initializer_list<std::string>& init)
- : std::vector<std::string>(init)
- { }
- /*!
- \param del the delimeter to be used when accumulating, default is an empty string
- \brief accumulates the contents of this container by the given delimeter
- */
- std::string acc(const std::string& del = "")
- {
- std::string r = "";
- for (auto it = this->begin(); it != this->end() - 1; ++it)
- r += *it + del;
- return r + this->at(this->size() - 1);
- }
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement