remove.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Range v3 library
  2. //
  3. // Copyright Andrey Diduh 2019
  4. //
  5. // Use, modification and distribution is subject to the
  6. // Boost Software License, Version 1.0. (See accompanying
  7. // file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // Project home: https://github.com/ericniebler/range-v3
  11. #include <vector>
  12. #include <string>
  13. #include <range/v3/action/remove.hpp>
  14. #include "../simple_test.hpp"
  15. #include "../test_utils.hpp"
  16. using namespace ranges;
  17. struct Data
  18. {
  19. int i;
  20. Data() = default;
  21. explicit Data(int j) : i(j) {}
  22. bool operator==(const Data& other) const {
  23. return other.i == i;
  24. }
  25. bool operator!=(const Data& other) const {
  26. return other.i != i;
  27. }
  28. };
  29. void simple_test()
  30. {
  31. std::vector<Data> list;
  32. list.emplace_back(Data{1});
  33. list.emplace_back(Data{2});
  34. list.emplace_back(Data{3});
  35. list.emplace_back(Data{4});
  36. Data d2{2};
  37. const auto remove_data = actions::remove(d2);
  38. list |= remove_data;
  39. check_equal(list, {Data{1}, Data{3}, Data{4}});
  40. list |= actions::remove(3, &Data::i);
  41. check_equal(list, {Data{1}, Data{4}});
  42. }
  43. void string_test()
  44. {
  45. std::vector<std::string> list = {"aaa", "bbb", "ccc"};
  46. list |= actions::remove("bbb");
  47. check_equal(list, {"aaa", "ccc"});
  48. }
  49. int main()
  50. {
  51. simple_test();
  52. string_test();
  53. return ::test_result();
  54. }