! @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 std::domain_error if called on JSON values other than arrays; example: `"cannot use insert() with string"`
| 5076 | @since version 1.0.0 |
| 5077 | */ |
| 5078 | iterator insert(const_iterator pos, const basic_json& val) |
| 5079 | { |
| 5080 | // insert only works for arrays |
| 5081 | if (is_array()) |
| 5082 | { |
| 5083 | // check if iterator pos fits to this JSON value |
| 5084 | if (pos.m_object != this) |
| 5085 | { |
| 5086 | throw std::domain_error("iterator does not fit current value"); |
| 5087 | } |
| 5088 | |
| 5089 | // insert to array and return iterator |
| 5090 | iterator result(this); |
| 5091 | result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val); |
| 5092 | return result; |
| 5093 | } |
| 5094 | else |
| 5095 | { |
| 5096 | throw std::domain_error("cannot use insert() with " + type_name()); |
| 5097 | } |
| 5098 | } |
| 5099 | |
| 5100 | /*! |
| 5101 | @brief inserts element |
no test coverage detected