From 0fc261f0f2be664f61d90499b662d35a7727f426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20F=2E=20Pozuelo?= Date: Fri, 3 Jul 2020 00:33:31 +0100 Subject: [PATCH] Make ordered_map compatible with GCC 5.5 --- include/nlohmann/ordered_map.hpp | 16 +++++++++++----- single_include/nlohmann/json.hpp | 18 ++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index 672eb31e..a6e006e6 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -11,16 +11,22 @@ namespace nlohmann /// ordered_map: a minimal map-like container that preserves insertion order /// for use within nlohmann::basic_json template , - class Allocator = std::allocator>> -struct ordered_map : std::vector + class Allocator = std::allocator>, + class Container = std::vector, Allocator>> +struct ordered_map : Container { - using Container = std::vector; using key_type = Key; using mapped_type = T; using typename Container::iterator; - using typename Container::value_type; using typename Container::size_type; - using Container::Container; + using typename Container::value_type; + + // Explicit constructors instead of `using Container::Container` + // otherwise older compilers like GCC 5.5 choke on it + ordered_map(const Allocator& alloc = Allocator()) : Container{alloc} {} + template + ordered_map(It first, It last, const Allocator& alloc = Allocator()) + : Container{first, last, alloc} {} std::pair emplace(key_type&& key, T&& t) { diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 0f8d48bd..50e173e2 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2773,7 +2773,7 @@ uses the standard template types. */ using json = basic_json<>; -template +template struct ordered_map; /*! @@ -15880,16 +15880,22 @@ namespace nlohmann /// ordered_map: a minimal map-like container that preserves insertion order /// for use within nlohmann::basic_json template , - class Allocator = std::allocator>> -struct ordered_map : std::vector + class Allocator = std::allocator>, + class Container = std::vector, Allocator>> +struct ordered_map : Container { - using Container = std::vector; using key_type = Key; using mapped_type = T; using typename Container::iterator; - using typename Container::value_type; using typename Container::size_type; - using Container::Container; + using typename Container::value_type; + + // Explicit constructors instead of `using Container::Container` + // otherwise older compilers like GCC 5.5 choke on it + ordered_map(const Allocator& alloc = Allocator()) : Container{alloc} {} + template + ordered_map(It first, It last, const Allocator& alloc = Allocator()) + : Container{first, last, alloc} {} std::pair emplace(key_type&& key, T&& t) {