Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

take_while.hpp 1.9KB

il y a 5 ans
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_TAKE_WHILE_HPP
  14. #define RANGES_V3_ACTION_TAKE_WHILE_HPP
  15. #include <range/v3/range_fwd.hpp>
  16. #include <range/v3/action/action.hpp>
  17. #include <range/v3/action/erase.hpp>
  18. #include <range/v3/algorithm/find_if_not.hpp>
  19. #include <range/v3/functional/bind_back.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 take_while_fn
  30. {
  31. private:
  32. friend action_access;
  33. template<typename Fun>
  34. static auto CPP_fun(bind)(take_while_fn take_while, Fun fun)( //
  35. requires(!range<Fun>))
  36. {
  37. return bind_back(take_while, std::move(fun));
  38. }
  39. public:
  40. template<typename Rng, typename Fun>
  41. auto operator()(Rng && rng, Fun fun) const -> CPP_ret(Rng)( //
  42. requires forward_range<Rng> &&
  43. erasable_range<Rng &, iterator_t<Rng>, sentinel_t<Rng>> &&
  44. indirect_unary_predicate<Fun, iterator_t<Rng>>)
  45. {
  46. ranges::actions::erase(
  47. rng, find_if_not(begin(rng), end(rng), std::move(fun)), end(rng));
  48. return static_cast<Rng &&>(rng);
  49. }
  50. };
  51. /// \ingroup group-actions
  52. /// \relates take_while_fn
  53. /// \sa action
  54. RANGES_INLINE_VARIABLE(action<take_while_fn>, take_while)
  55. } // namespace actions
  56. /// @}
  57. } // namespace ranges
  58. #endif