Skip to content

Commit

Permalink
Patch nlohmann/json for GCC 4.8
Browse files Browse the repository at this point in the history
See nlohmann/json#212 for details
  • Loading branch information
cjh1 committed Sep 20, 2018
1 parent 0a5ec6d commit fce3586
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion thirdparty/nlohmann/detail/macro_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
#endif
#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
#error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
#endif
#endif
Expand Down
36 changes: 21 additions & 15 deletions thirdparty/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4943,6 +4943,23 @@ class basic_json
return {it, res.second};
}

/// helper for insertion of an iterator (supports GCC 4.8+)
template<typename... Args>
iterator insert_iterator(const_iterator pos, Args&& ... args)
{
iterator result(this);
assert(m_value.array != nullptr);

auto insert_pos = std::distance(m_value.array->begin(), pos.m_it.array_iterator);
m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
result.m_it.array_iterator = m_value.array->begin() + insert_pos;

// For GCC 4.9+ only, this could become:
// result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);

return result;
}

/*!
@brief inserts element
Expand Down Expand Up @@ -4977,9 +4994,7 @@ class basic_json
}

// insert to array and return iterator
iterator result(this);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
return result;
return insert_iterator(pos, val);
}

JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
Expand Down Expand Up @@ -5030,9 +5045,7 @@ class basic_json
}

// insert to array and return iterator
iterator result(this);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
return result;
return insert_iterator(pos, cnt, val);
}

JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
Expand Down Expand Up @@ -5094,12 +5107,7 @@ class basic_json
}

// insert to array and return iterator
iterator result(this);
result.m_it.array_iterator = m_value.array->insert(
pos.m_it.array_iterator,
first.m_it.array_iterator,
last.m_it.array_iterator);
return result;
return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
}

/*!
Expand Down Expand Up @@ -5141,9 +5149,7 @@ class basic_json
}

// insert to array and return iterator
iterator result(this);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist.begin(), ilist.end());
return result;
return insert_iterator(pos, ilist.begin(), ilist.end());
}

/*!
Expand Down

0 comments on commit fce3586

Please sign in to comment.