Skip to content

Commit

Permalink
external: manually apply GCC 4.8 support patch on json.hpp.
Browse files Browse the repository at this point in the history
This allows us to build the TinyGltfImporter on GCC 4.8. It was disabled
until now on Linux because the Travis builds were using GCC 4.7 and
json.hpp required 4.9, but now that we're dropping 4.7 support, it makes
sense to go an extra step and have this built under 4.8 as well.

Taken from nlohmann/json#1257, applied the part
that touches single_include/nlohmann/json.hpp skipping the compiler
check on top (which doesn't apply) and doing the change by hand.

I could also update to json.hpp 3.3 / 3.4, but that version is 700 kB
(vs 480 kB for this one) and I have no reason to use that. I also hope
I'll never need to update this thing again.
  • Loading branch information
mosra committed Dec 14, 2018
1 parent 25f3755 commit 6dcad17
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/MagnumExternal/TinyGltf/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ SOFTWARE.
#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 Expand Up @@ -11832,6 +11832,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 @@ -11866,9 +11883,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 @@ -11919,9 +11934,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 @@ -11983,12 +11996,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 @@ -12030,9 +12038,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 6dcad17

Please sign in to comment.