fork download
  1. #include <vector>
  2. #include <string>
  3.  
  4. class ListBuilder {
  5. private:
  6. std::vector<std::string> data;
  7. public:
  8. ListBuilder& operator<<(const std::string& str) {
  9. data.push_back(str);
  10. return *this;
  11. }
  12. void clear() {
  13. data.clear();
  14. }
  15.  
  16. std::vector<std::string> getData() const {
  17. return data;
  18. }
  19. };
  20.  
  21. #include <iostream>
  22.  
  23. int main() {
  24. auto vec = (ListBuilder() << "hello" << "world" << "!").getData();
  25. for(auto& i : vec)
  26. std::cout << i << '\n';
  27. std::cout << vec.size();
  28. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
hello
world
!
3