You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

indices.hpp 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler 2013-present
  5. // Copyright Gonzalo Brito Gadeschi
  6. //
  7. // Use, modification and distribution is subject to the
  8. // Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. //
  12. // Project home: https://github.com/ericniebler/range-v3
  13. //
  14. #ifndef RANGES_V3_VIEW_INDICES_HPP
  15. #define RANGES_V3_VIEW_INDICES_HPP
  16. #include <meta/meta.hpp>
  17. #include <range/v3/range_fwd.hpp>
  18. #include <range/v3/range/concepts.hpp>
  19. #include <range/v3/utility/static_const.hpp>
  20. #include <range/v3/view/iota.hpp>
  21. #include <range/v3/view/take_exactly.hpp>
  22. namespace ranges
  23. {
  24. namespace views
  25. {
  26. /// Half-open range of indices: [from, to).
  27. struct indices_fn : iota_view<std::size_t>
  28. {
  29. indices_fn() = default;
  30. template<typename Val>
  31. auto operator()(Val to) const -> CPP_ret(iota_view<Val, Val>)( //
  32. requires integral<Val>)
  33. {
  34. return {Val(), to};
  35. }
  36. template<typename Val>
  37. auto operator()(Val from, Val to) const -> CPP_ret(iota_view<Val, Val>)( //
  38. requires integral<Val>)
  39. {
  40. return {from, to};
  41. }
  42. };
  43. /// Inclusive range of indices: [from, to].
  44. struct closed_indices_fn
  45. {
  46. template<typename Val>
  47. auto operator()(Val to) const -> CPP_ret(closed_iota_view<Val>)( //
  48. requires integral<Val>)
  49. {
  50. return {Val(), to};
  51. }
  52. template<typename Val>
  53. auto operator()(Val from, Val to) const -> CPP_ret(closed_iota_view<Val>)( //
  54. requires integral<Val>)
  55. {
  56. return {from, to};
  57. }
  58. };
  59. /// \relates indices_fn
  60. /// \ingroup group-views
  61. RANGES_INLINE_VARIABLE(indices_fn, indices)
  62. /// \relates closed_indices_fn
  63. /// \ingroup group-views
  64. RANGES_INLINE_VARIABLE(closed_indices_fn, closed_indices)
  65. } // namespace views
  66. } // namespace ranges
  67. #endif // RANGES_V3_VIEW_INDICES_HPP