Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

65 linhas
1.9KB

  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-present
  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. #ifndef RANGES_V3_ACTION_TRANSFORM_HPP
  14. #define RANGES_V3_ACTION_TRANSFORM_HPP
  15. #include <range/v3/range_fwd.hpp>
  16. #include <range/v3/action/action.hpp>
  17. #include <range/v3/algorithm/transform.hpp>
  18. #include <range/v3/functional/bind_back.hpp>
  19. #include <range/v3/functional/identity.hpp>
  20. #include <range/v3/iterator/concepts.hpp>
  21. #include <range/v3/iterator/traits.hpp>
  22. #include <range/v3/utility/static_const.hpp>
  23. namespace ranges
  24. {
  25. /// \addtogroup group-actions
  26. /// @{
  27. namespace actions
  28. {
  29. struct transform_fn
  30. {
  31. private:
  32. friend action_access;
  33. template<typename F, typename P = identity>
  34. static auto CPP_fun(bind)(transform_fn transform, F fun, P proj = P{})( //
  35. requires(!range<F>))
  36. {
  37. return bind_back(transform, std::move(fun), std::move(proj));
  38. }
  39. public:
  40. template<typename Rng, typename F, typename P = identity>
  41. auto operator()(Rng && rng, F fun, P proj = P{}) const -> CPP_ret(Rng)( //
  42. requires input_range<Rng> && copy_constructible<F> &&
  43. writable<iterator_t<Rng>,
  44. indirect_result_t<F &, projected<iterator_t<Rng>, P>>>)
  45. {
  46. ranges::transform(rng, begin(rng), std::move(fun), std::move(proj));
  47. return static_cast<Rng &&>(rng);
  48. }
  49. };
  50. /// \ingroup group-actions
  51. /// \relates transform_fn
  52. /// \sa action
  53. RANGES_INLINE_VARIABLE(action<transform_fn>, transform)
  54. } // namespace actions
  55. /// @}
  56. } // namespace ranges
  57. #endif