Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <deque>
- #include <set>
- #include <boost/format.hpp>
- #include <algorithm>
- class foo {
- std::deque< std::set<std::string> > q;
- public:
- void dump() {
- int cnt = 0;
- std::string res("");
- for ( std::deque<std::set<std::string> >::iterator i = q.begin();
- i != q.end();
- ++i, ++cnt ) {
- res += (boost::format("Q%d[") % cnt).str();
- for ( std::set<std::string>::iterator j = i->begin();
- j != i->end();
- ++j ) {
- res += *j;
- res += ", ";
- }
- res += "] ";
- }
- std::cout << "dump: " << res << "\n";
- }
- void add_set() {
- q.push_back(std::set<std::string>());
- }
- void add_str(std::string s) {
- q.back().insert(s);
- }
- void operator()(std::string s) {
- add_set();
- add_str(s);
- }
- };
- int main() {
- std::vector< std::string > v;
- foo f;
- v.push_back("string1");
- f.dump();
- // for_each(v.begin(), v.end(), f);
- for(std::vector< std::string >::iterator i = v.begin();
- i != v.end();
- ++i) {
- f(*i);
- }
- f.dump();
- }
Add Comment
Please, Sign In to add comment