transform.cpp 980 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Range v3 library
  2. //
  3. // Copyright Eric Niebler 2014-present
  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. #include <array>
  10. #include <vector>
  11. #include <range/v3/core.hpp>
  12. #include <range/v3/view/iota.hpp>
  13. #include <range/v3/algorithm/copy.hpp>
  14. #include <range/v3/algorithm/move.hpp>
  15. #include <range/v3/algorithm/equal.hpp>
  16. #include <range/v3/action/transform.hpp>
  17. #include "../simple_test.hpp"
  18. #include "../test_utils.hpp"
  19. int main()
  20. {
  21. using namespace ranges;
  22. auto v = views::ints(0,10) | to<std::vector>();
  23. auto v0 = v | copy | actions::transform([](int i){return i*i;});
  24. CPP_assert(same_as<decltype(v), decltype(v0)>);
  25. ::check_equal(v0, {0,1,4,9,16,25,36,49,64,81});
  26. actions::transform(v, [](int i){return i*i;});
  27. ::check_equal(v, {0,1,4,9,16,25,36,49,64,81});
  28. return ::test_result();
  29. }