! @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 u
| 22019 | @since version 1.0.0 |
| 22020 | */ |
| 22021 | iterator insert(const_iterator pos, const basic_json& val) |
| 22022 | { |
| 22023 | // insert only works for arrays |
| 22024 | if (JSON_HEDLEY_LIKELY(is_array())) |
| 22025 | { |
| 22026 | // check if iterator pos fits to this JSON value |
| 22027 | if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) |
| 22028 | { |
| 22029 | JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value")); |
| 22030 | } |
| 22031 | |
| 22032 | // insert to array and return iterator |
| 22033 | return insert_iterator(pos, val); |
| 22034 | } |
| 22035 | |
| 22036 | JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()))); |
| 22037 | } |
| 22038 | |
| 22039 | /*! |
| 22040 | @brief inserts element |