! @brief inserts element Inserts element @a val before iterator @a pos. @param[in] pos iterator before which the content will be inserted; may be the end() iterator @param[in] val element to insert @return iterator pointing to the inserted @a val. @throw type_error.309 if called on JSON values other than arrays; example: `"cannot use insert() with string"` @t
| 23264 | @since version 1.0.0 |
| 23265 | */ |
| 23266 | iterator insert(const_iterator pos, const basic_json& val) |
| 23267 | { |
| 23268 | // insert only works for arrays |
| 23269 | if (JSON_HEDLEY_LIKELY(is_array())) |
| 23270 | { |
| 23271 | // check if iterator pos fits to this JSON value |
| 23272 | if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) |
| 23273 | { |
| 23274 | JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this)); |
| 23275 | } |
| 23276 | |
| 23277 | // insert to array and return iterator |
| 23278 | return insert_iterator(pos, val); |
| 23279 | } |
| 23280 | |
| 23281 | JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this)); |
| 23282 | } |
| 23283 | |
| 23284 | /*! |
| 23285 | @brief inserts element |