| 76 | // push_back(typeof T::operator[](int())) |
| 77 | template <typename Res, typename In> |
| 78 | Res slice(In const& r, SliceIndex a, SliceIndex b = SliceIndex(), int j = 1) { |
| 79 | int size = (int)r.size(); |
| 80 | int start, end; |
| 81 | |
| 82 | // Throw exception on j == 0? |
| 83 | if (j == 0 || size == 0) |
| 84 | return Res(); |
| 85 | |
| 86 | if (!a.given) { |
| 87 | if (j > 0) |
| 88 | start = 0; |
| 89 | else |
| 90 | start = size - 1; |
| 91 | } else if (a.index < 0) { |
| 92 | if (-a.index > size - 1) |
| 93 | start = 0; |
| 94 | else |
| 95 | start = size - -a.index; |
| 96 | } else { |
| 97 | if (a.index > size) |
| 98 | start = size; |
| 99 | else |
| 100 | start = a.index; |
| 101 | } |
| 102 | |
| 103 | if (!b.given) { |
| 104 | if (j > 0) |
| 105 | end = size; |
| 106 | else |
| 107 | end = -1; |
| 108 | } else if (b.index < 0) { |
| 109 | if (-b.index > size - 1) { |
| 110 | end = -1; |
| 111 | } else { |
| 112 | end = size - -b.index; |
| 113 | } |
| 114 | } else { |
| 115 | if (b.index > size - 1) { |
| 116 | end = size; |
| 117 | } else { |
| 118 | end = b.index; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | if (start < end && j < 0) |
| 123 | return Res(); |
| 124 | if (start > end && j > 0) |
| 125 | return Res(); |
| 126 | |
| 127 | Res returnSlice; |
| 128 | int i; |
| 129 | for (i = start; i < end; i += j) |
| 130 | returnSlice.push_back(r[i]); |
| 131 | |
| 132 | return returnSlice; |
| 133 | } |
| 134 | |
| 135 | template <typename T> |
no test coverage detected