Skip to content

Commit 6dcad17

Browse files
committed
external: manually apply GCC 4.8 support patch on json.hpp.
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.
1 parent 25f3755 commit 6dcad17

1 file changed

Lines changed: 22 additions & 16 deletions

File tree

src/MagnumExternal/TinyGltf/json.hpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ SOFTWARE.
6363
#error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
6464
#endif
6565
#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
66-
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900
66+
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
6767
#error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
6868
#endif
6969
#endif
@@ -11832,6 +11832,23 @@ class basic_json
1183211832
return {it, res.second};
1183311833
}
1183411834

11835+
/// helper for insertion of an iterator (supports GCC 4.8+)
11836+
template<typename... Args>
11837+
iterator insert_iterator(const_iterator pos, Args&& ... args)
11838+
{
11839+
iterator result(this);
11840+
assert(m_value.array != nullptr);
11841+
11842+
auto insert_pos = std::distance(m_value.array->begin(), pos.m_it.array_iterator);
11843+
m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
11844+
result.m_it.array_iterator = m_value.array->begin() + insert_pos;
11845+
11846+
// For GCC 4.9+ only, this could become:
11847+
// result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
11848+
11849+
return result;
11850+
}
11851+
1183511852
/*!
1183611853
@brief inserts element
1183711854
@@ -11866,9 +11883,7 @@ class basic_json
1186611883
}
1186711884

1186811885
// insert to array and return iterator
11869-
iterator result(this);
11870-
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
11871-
return result;
11886+
return insert_iterator(pos, val);
1187211887
}
1187311888

1187411889
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
@@ -11919,9 +11934,7 @@ class basic_json
1191911934
}
1192011935

1192111936
// insert to array and return iterator
11922-
iterator result(this);
11923-
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
11924-
return result;
11937+
return insert_iterator(pos, cnt, val);
1192511938
}
1192611939

1192711940
JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name())));
@@ -11983,12 +11996,7 @@ class basic_json
1198311996
}
1198411997

1198511998
// insert to array and return iterator
11986-
iterator result(this);
11987-
result.m_it.array_iterator = m_value.array->insert(
11988-
pos.m_it.array_iterator,
11989-
first.m_it.array_iterator,
11990-
last.m_it.array_iterator);
11991-
return result;
11999+
return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
1199212000
}
1199312001

1199412002
/*!
@@ -12030,9 +12038,7 @@ class basic_json
1203012038
}
1203112039

1203212040
// insert to array and return iterator
12033-
iterator result(this);
12034-
result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist.begin(), ilist.end());
12035-
return result;
12041+
return insert_iterator(pos, ilist.begin(), ilist.end());
1203612042
}
1203712043

1203812044
/*!

0 commit comments

Comments
 (0)