From 6ee9e5f40287202852b3b73fbaca97be9338328d Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 20 Jun 2020 13:23:44 +0200 Subject: [PATCH] :alembic: remove const from value type --- include/nlohmann/ordered_map.hpp | 38 ++++++++++++--------------- single_include/nlohmann/json.hpp | 44 +++++++++++++++----------------- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index 744541f3ab..2cf33c425c 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -10,14 +10,15 @@ namespace nlohmann /// ordered_map: a minimal map-like container that preserves insertion order /// for use within nlohmann::basic_json -template, - class Allocator = std::allocator>, - class Container = std::vector, Allocator>> +template , + class Allocator = std::allocator>, + class Container = std::vector, Allocator>> struct ordered_map : Container { using key_type = Key; using mapped_type = T; - using value_type = std::pair; + using value_type = typename Container::value_type; + using size_type = typename Container::size_type; using Container::Container; std::pair emplace(key_type&& key, T&& t) @@ -29,33 +30,26 @@ struct ordered_map : Container return {it, false}; } } - - this->emplace_back(key, t); + Container::emplace_back(key, t); return {--this->end(), true}; } - std::size_t erase(const key_type& key) + T& operator[](Key&& key) { - std::size_t result = 0; - for (auto it = this->begin(); it != this->end();) + return emplace(std::move(key), T{}).first->second; + } + + size_type erase(const Key& key) + { + for (auto it = this->begin(); it != this->end(); ++it) { if (it->first == key) { - ++result; - it = Container::erase(it); - } - else - { - ++it; + Container::erase(it); + return 1; } } - - return result; - } - - T& operator[](key_type&& key) - { - return emplace(std::move(key), T{}).first->second; + return 0; } }; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index f7f1664ecc..c8cabbbf07 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2777,6 +2777,10 @@ template; @@ -15875,17 +15879,18 @@ namespace nlohmann /// ordered_map: a minimal map-like container that preserves insertion order /// for use within nlohmann::basic_json -template, - class Allocator = std::allocator>, - class Container = std::vector, Allocator>> +template , + class Allocator = std::allocator>, + class Container = std::vector, Allocator>> struct ordered_map : Container { using key_type = Key; using mapped_type = T; - using value_type = std::pair; + using value_type = typename Container::value_type; + using size_type = typename Container::size_type; using Container::Container; - std::pair emplace(Key&& key, T&& t) + std::pair emplace(key_type&& key, T&& t) { for (auto it = this->begin(); it != this->end(); ++it) { @@ -15894,33 +15899,26 @@ struct ordered_map : Container return {it, false}; } } - - this->emplace_back(key, t); + Container::emplace_back(key, t); return {--this->end(), true}; } - std::size_t erase(const Key& key) + T& operator[](Key&& key) { - std::size_t result = 0; - for (auto it = this->begin(); it != this->end(); ) + return emplace(std::move(key), T{}).first->second; + } + + size_type erase(const Key& key) + { + for (auto it = this->begin(); it != this->end(); ++it) { if (it->first == key) { - ++result; - it = Container::erase(it); - } - else - { - ++it; + Container::erase(it); + return 1; } } - - return result; - } - - T& operator[]( Key&& key ) - { - return emplace(std::move(key), T{}).first->second; + return 0; } };