From 2905bdebefe30112556e2f8f9cfd68d080094c48 Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 15 Oct 2017 23:36:00 +0100 Subject: [PATCH] make vector friendly to gcc < 5 --- src/util/vector.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/util/vector.h b/src/util/vector.h index 27de49c44..f5792a5d3 100644 --- a/src/util/vector.h +++ b/src/util/vector.h @@ -76,25 +76,26 @@ class vector { throw default_exception("Overflow encountered when expanding vector"); } SZ *mem, *old_mem = reinterpret_cast(m_data) - 2; +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5 + if (__has_trivial_copy(T)) { +#else if (std::is_trivially_copyable::value) { +#endif mem = (SZ*)memory::reallocate(old_mem, new_capacity_T); + m_data = reinterpret_cast(mem + 2); } else { mem = (SZ*)memory::allocate(new_capacity_T); - } - auto old_data = m_data; - auto old_size = size(); - *mem = new_capacity; - m_data = reinterpret_cast(mem + 2); - if (!std::is_trivially_copyable::value) { - static_assert(std::is_move_constructible::value, ""); + auto old_data = m_data; + auto old_size = size(); mem[1] = old_size; - int i = 0; - for (auto I = old_data; I != old_data + old_size; ++I) { - new (&m_data[i++]) T(std::move(*I)); - I->~T(); + m_data = reinterpret_cast(mem + 2); + for (unsigned i = 0; i < old_size; ++i) { + new (&m_data[i]) T(std::move(old_data[i])); + old_data[i].~T(); } memory::deallocate(old_mem); } + *mem = new_capacity; } }