remove.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Andrey Diduh 2019
  5. //
  6. // Use, modification and distribution is subject to the
  7. // Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // Project home: https://github.com/ericniebler/range-v3
  12. //
  13. #include <vector>
  14. #include <range/v3/view/remove.hpp>
  15. #include <range/v3/view/remove_if.hpp>
  16. #include "../simple_test.hpp"
  17. #include "../test_utils.hpp"
  18. using namespace ranges;
  19. void test_straight()
  20. {
  21. std::vector<int> vec = {1,2,3,4,5};
  22. auto out = vec | views::remove(2);
  23. ::check_equal(out, {1,3,4,5});
  24. }
  25. struct Int
  26. {
  27. int i;
  28. };
  29. bool operator==(Int left, Int right)
  30. {
  31. return left.i == right.i;
  32. }
  33. void test_proj()
  34. {
  35. const std::vector<Int> vec{ Int{1}, Int{2}, Int{3}, Int{4}, Int{5} };
  36. auto out = vec | views::remove(2, &Int::i);
  37. ::check_equal(out, {Int{1}, Int{3}, Int{4}, Int{5}});
  38. }
  39. int main()
  40. {
  41. // simple interface tests.
  42. // All other already tested in remove_if.
  43. test_straight();
  44. test_proj();
  45. return test_result();
  46. }