fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. class both_equal_to
  6. {
  7. char value;
  8. public:
  9. both_equal_to(char ch) : value(ch) {}
  10.  
  11. bool operator()(char first, char second) const
  12. {
  13. return (first == second) && (first == value);
  14. }
  15. };
  16.  
  17. int main()
  18. {
  19. std::string text("_hello___world__");
  20.  
  21. text.erase(
  22. std::unique(
  23. text.begin(),
  24. text.end(),
  25. both_equal_to('_')
  26. // [](char a, char b){ return (a == '_') && (b == '_'); }
  27. ),
  28. text.end()
  29. );
  30.  
  31. std::cout << text << '\n';
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
_hello_world_