| 141 | /// Algorithm for inserting at a specific position into a container |
| 142 | template<typename Type> |
| 143 | void insert_at(Type &container, int pos, const typename Type::value_type &v) |
| 144 | { |
| 145 | auto itr = container.begin(); |
| 146 | auto end = container.end(); |
| 147 | |
| 148 | if (pos < 0 || std::distance(itr, end) < pos) |
| 149 | { |
| 150 | throw std::range_error("Cannot insert past end of range"); |
| 151 | } |
| 152 | |
| 153 | std::advance(itr, pos); |
| 154 | container.insert(itr, v); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /// Algorithm for erasing a specific position from a container |