| 69 | */ |
| 70 | template<typename T> |
| 71 | static T slice(const T & array, int64_t start, int64_t stop, int64_t step = 1) { |
| 72 | int64_t len = static_cast<int64_t>(array.size()); |
| 73 | int64_t direction = (step > 0) ? 1 : ((step < 0) ? -1 : 0); |
| 74 | int64_t start_val = 0; |
| 75 | int64_t stop_val = 0; |
| 76 | if (direction >= 0) { |
| 77 | start_val = start; |
| 78 | if (start_val < 0) { |
| 79 | start_val = std::max(len + start_val, (int64_t)0); |
| 80 | } else { |
| 81 | start_val = std::min(start_val, len); |
| 82 | } |
| 83 | |
| 84 | stop_val = stop; |
| 85 | if (stop_val < 0) { |
| 86 | stop_val = std::max(len + stop_val, (int64_t)0); |
| 87 | } else { |
| 88 | stop_val = std::min(stop_val, len); |
| 89 | } |
| 90 | } else { |
| 91 | start_val = len - 1; |
| 92 | if (start_val < 0) { |
| 93 | start_val = std::max(len + start_val, (int64_t)-1); |
| 94 | } else { |
| 95 | start_val = std::min(start_val, len - 1); |
| 96 | } |
| 97 | |
| 98 | stop_val = -1; |
| 99 | if (stop_val < -1) { |
| 100 | stop_val = std::max(len + stop_val, (int64_t)-1); |
| 101 | } else { |
| 102 | stop_val = std::min(stop_val, len - 1); |
| 103 | } |
| 104 | } |
| 105 | T result; |
| 106 | if (direction == 0) { |
| 107 | return result; |
| 108 | } |
| 109 | for (int64_t i = start_val; direction * i < direction * stop_val; i += step) { |
| 110 | if (i >= 0 && i < len) { |
| 111 | result.push_back(array[static_cast<size_t>(i)]); |
| 112 | } |
| 113 | } |
| 114 | return result; |
| 115 | } |
| 116 | |
| 117 | template<typename T> |
| 118 | static value empty_value_fn(const func_args &) { |
no test coverage detected