Patch nlohmann/json for GCC 4.8

See https://github.com/nlohmann/json/pull/212 for details
This commit is contained in:
Chris Harris 2018-09-20 11:19:33 -04:00 committed by Henry Fredrick Schreiner
parent e184b6ecf2
commit 99b7c7c8ef
3 changed files with 44 additions and 32 deletions

View file

@ -10,7 +10,7 @@
#error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
#endif #endif
#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) #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" #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
#endif #endif
#endif #endif

View file

@ -4943,6 +4943,23 @@ class basic_json
return {it, res.second}; 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 @brief inserts element
@ -4977,9 +4994,7 @@ class basic_json
} }
// insert to array and return iterator // insert to array and return iterator
iterator result(this); return insert_iterator(pos, val);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
return result;
} }
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()))); JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
@ -5030,9 +5045,7 @@ class basic_json
} }
// insert to array and return iterator // insert to array and return iterator
iterator result(this); return insert_iterator(pos, cnt, val);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
return result;
} }
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()))); JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
@ -5094,12 +5107,7 @@ class basic_json
} }
// insert to array and return iterator // insert to array and return iterator
iterator result(this); return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
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;
} }
/*! /*!
@ -5141,9 +5149,7 @@ class basic_json
} }
// insert to array and return iterator // insert to array and return iterator
iterator result(this); return insert_iterator(pos, ilist.begin(), ilist.end());
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist.begin(), ilist.end());
return result;
} }
/*! /*!

View file

@ -125,7 +125,7 @@ using json = basic_json<>;
#error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
#endif #endif
#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) #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" #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
#endif #endif
#endif #endif
@ -16016,6 +16016,23 @@ class basic_json
return {it, res.second}; 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 @brief inserts element
@ -16050,9 +16067,7 @@ class basic_json
} }
// insert to array and return iterator // insert to array and return iterator
iterator result(this); return insert_iterator(pos, val);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
return result;
} }
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()))); JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
@ -16103,9 +16118,7 @@ class basic_json
} }
// insert to array and return iterator // insert to array and return iterator
iterator result(this); return insert_iterator(pos, cnt, val);
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
return result;
} }
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()))); JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
@ -16167,12 +16180,7 @@ class basic_json
} }
// insert to array and return iterator // insert to array and return iterator
iterator result(this); return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
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;
} }
/*! /*!
@ -16214,9 +16222,7 @@ class basic_json
} }
// insert to array and return iterator // insert to array and return iterator
iterator result(this); return insert_iterator(pos, ilist.begin(), ilist.end());
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist.begin(), ilist.end());
return result;
} }
/*! /*!