support gcc 4.8.1 by abc100m · Pull Request #212 · nlohmann/json (original) (raw)
This is what I'm thinking:
@@ -123,7 +123,7 @@ using json = basic_json<>; #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 @@ -10435,6 +10435,23 @@ class basic_json return object.release(); }
- /// 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;
- }
//////////////////////// // JSON value storage // ////////////////////////
@@ -14579,9 +14596,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())));
@@ -14632,9 +14647,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())));
@@ -14696,12 +14709,10 @@ 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);
}
/*!
@@ -14743,9 +14754,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());
}
/*!
That would reduce maintenance burden by factoring out similar code into one place, and would also support GCC 4.8 partially. It could also be done with the #if
.
(I've left in the old assert, but it seems to not be in the current .hpp, so you could remove it. It's just in one place now instead of three.)