bind_back.cpp 789 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Range v3 library
  2. //
  3. // Copyright Eric Niebler 2020
  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 <range/v3/functional/bind_back.hpp>
  12. #include <range/v3/functional/concepts.hpp>
  13. #include "../simple_test.hpp"
  14. using namespace ranges;
  15. int* test(int & i)
  16. {
  17. return &i;
  18. }
  19. int main()
  20. {
  21. int i = 42;
  22. auto fn = bind_back(test, i);
  23. int* pi = fn();
  24. CHECK(pi != &i);
  25. CHECK(*pi == i);
  26. CPP_assert(!invocable<decltype(fn)>);
  27. CPP_assert(invocable<decltype(fn) &>);
  28. CPP_assert(!invocable<decltype(fn) const &>);
  29. return ::test_result();
  30. }