fork download
  1. #include <algorithm>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <set>
  6. #include <string_view>
  7.  
  8. template<typename T>
  9. std::ostream& operator<<(std::ostream& out, const std::set<T>& set)
  10. {
  11. if (set.empty())
  12. return out << "{}";
  13. out << "{ " << *set.begin();
  14. std::for_each(std::next(set.begin()), set.end(), [&out](const T& element)
  15. {
  16. out << ", " << element;
  17. });
  18. return out << " }";
  19. }
  20. void test(std::set<int> s)
  21. {
  22. std::cout << s << " in test " << '\n';
  23. }
  24. int main()
  25. {
  26. std::set<int> set;
  27. test(std::move(set));
  28.  
  29. set.insert(2);
  30. std::cout << set << '\n';
  31.  
  32. set.erase(1);
  33. std::cout << set << "\n\n";
  34.  
  35. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
{} in test 
{ 2 }
{ 2 }