Guest User

Untitled

a guest
Jan 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <deque>
  4. #include <set>
  5. #include <boost/format.hpp>
  6. #include <algorithm>
  7.  
  8. class foo {
  9. std::deque< std::set<std::string> > q;
  10. public:
  11. void dump() {
  12. int cnt = 0;
  13. std::string res("");
  14. for ( std::deque<std::set<std::string> >::iterator i = q.begin();
  15. i != q.end();
  16. ++i, ++cnt ) {
  17. res += (boost::format("Q%d[") % cnt).str();
  18. for ( std::set<std::string>::iterator j = i->begin();
  19. j != i->end();
  20. ++j ) {
  21. res += *j;
  22. res += ", ";
  23. }
  24. res += "] ";
  25. }
  26. std::cout << "dump: " << res << "\n";
  27. }
  28.  
  29. void add_set() {
  30. q.push_back(std::set<std::string>());
  31. }
  32.  
  33. void add_str(std::string s) {
  34. q.back().insert(s);
  35. }
  36.  
  37. void operator()(std::string s) {
  38. add_set();
  39. add_str(s);
  40. }
  41. };
  42.  
  43. int main() {
  44. std::vector< std::string > v;
  45. foo f;
  46.  
  47. v.push_back("string1");
  48.  
  49. f.dump();
  50.  
  51. // for_each(v.begin(), v.end(), f);
  52. for(std::vector< std::string >::iterator i = v.begin();
  53. i != v.end();
  54. ++i) {
  55. f(*i);
  56. }
  57.  
  58. f.dump();
  59. }
Add Comment
Please, Sign In to add comment