| 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 |
|
| 15 |
#ifndef RANGES_V3_VIEW_INDICES_HPP |
| 16 |
#define RANGES_V3_VIEW_INDICES_HPP |
| 17 |
|
| 18 |
#include <meta/meta.hpp> |
| 19 |
|
| 20 |
#include <range/v3/range_fwd.hpp> |
| 21 |
|
| 22 |
#include <range/v3/range/concepts.hpp> |
| 23 |
#include <range/v3/utility/static_const.hpp> |
| 24 |
#include <range/v3/view/iota.hpp> |
| 25 |
|
| 26 |
#include <range/v3/detail/prologue.hpp> |
| 27 |
|
| 28 |
namespace ranges |
| 29 |
{ |
| 30 |
namespace views |
| 31 |
{ |
| 32 |
/// Half-open range of indices: [from, to). |
| 33 |
struct indices_fn : iota_view<std::size_t> |
| 34 |
{ |
| 35 |
indices_fn() = default; |
| 36 |
|
| 37 |
template(typename Val)( |
| 38 |
requires integral<Val>) |
| 39 |
iota_view<Val, Val> operator()(Val to) const |
| 40 |
{ |
| 41 |
return {Val(), to}; |
| 42 |
} |
| 43 |
template(typename Val)( |
| 44 |
requires integral<Val>) |
| 45 |
iota_view<Val, Val> operator()(Val from, Val to) const |
| 46 |
{ |
| 47 |
return {from, to}; |
| 48 |
} |
| 49 |
}; |
| 50 |
|
| 51 |
/// Inclusive range of indices: [from, to]. |
| 52 |
struct closed_indices_fn |
| 53 |
{ |
| 54 |
template(typename Val)( |
| 55 |
requires integral<Val>) |
| 56 |
closed_iota_view<Val> operator()(Val to) const |
| 57 |
{ |
| 58 |
return {Val(), to}; |
| 59 |
} |
| 60 |
template(typename Val)( |
| 61 |
requires integral<Val>) |
| 62 |
closed_iota_view<Val> operator()(Val from, Val to) const |
| 63 |
{ |
| 64 |
return {from, to}; |
| 65 |
} |
| 66 |
}; |
| 67 |
|
| 68 |
/// \relates indices_fn |
| 69 |
/// \ingroup group-views |
| 70 |
RANGES_INLINE_VARIABLE(indices_fn, indices) |
| 71 |
|
| 72 |
/// \relates closed_indices_fn |
| 73 |
/// \ingroup group-views |
| 74 |
RANGES_INLINE_VARIABLE(closed_indices_fn, closed_indices) |
| 75 |
} // namespace views |
| 76 |
} // namespace ranges |
| 77 |
|
| 78 |
#include <range/v3/detail/epilogue.hpp> |
| 79 |
|
| 80 |
#endif // RANGES_V3_VIEW_INDICES_HPP |