From ddf0a45abbbb348142919adf3d9d8212ee998f53 Mon Sep 17 00:00:00 2001 From: gatopeich Date: Mon, 22 Jun 2020 18:35:46 +0100 Subject: [PATCH] Use AllocatorType, instead of hard-coding it for std::map's value_type --- .gitignore | 2 ++ README.md | 2 +- doc/mkdocs/docs/features/types.md | 2 +- include/nlohmann/json.hpp | 4 +--- include/nlohmann/ordered_map.hpp | 4 ++-- single_include/nlohmann/json.hpp | 8 +++----- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 9d4fcb37..4a39c874 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,8 @@ cmake-build-debug test/test-* test/test_data.hpp +Temporary + /.vs .vscode diff --git a/README.md b/README.md index d7492da3..972d857f 100644 --- a/README.md +++ b/README.md @@ -1527,7 +1527,7 @@ This library will not support comments in the future. If you wish to use comment ### Order of object keys -By default, the library does not preserve the **insertion order of object elements**. This is standards-compliant, as the [JSON standard](https://tools.ietf.org/html/rfc8259.html) defines objects as "an unordered collection of zero or more name/value pairs". If you do want to preserve the insertion order, you can specialize the object type with containers like [`tsl::ordered_map`](https://github.com/Tessil/ordered-map) ([integration](https://github.com/nlohmann/json/issues/546#issuecomment-304447518)) or [`nlohmann::fifo_map`](https://github.com/nlohmann/fifo_map) ([integration](https://github.com/nlohmann/json/issues/485#issuecomment-333652309)). +By default, the library does not preserve the **insertion order of object elements**. This is standards-compliant, as the [JSON standard](https://tools.ietf.org/html/rfc8259.html) defines objects as "an unordered collection of zero or more name/value pairs". If you do want to preserve the insertion order, you can try the new [`nlohmann::ordered_json`](https://github.com/nlohmann/json/issues/2179) specialization, or use a more sophisticated ordered map like [`tsl::ordered_map`](https://github.com/Tessil/ordered-map) ([integration](https://github.com/nlohmann/json/issues/546#issuecomment-304447518)) or [`nlohmann::fifo_map`](https://github.com/nlohmann/fifo_map) ([integration](https://github.com/nlohmann/json/issues/485#issuecomment-333652309)). ### Memory Release diff --git a/doc/mkdocs/docs/features/types.md b/doc/mkdocs/docs/features/types.md index 94e40cba..7754bbca 100644 --- a/doc/mkdocs/docs/features/types.md +++ b/doc/mkdocs/docs/features/types.md @@ -89,7 +89,7 @@ From the template arguments, the following types are derived: ```cpp using object_comparator_t = std::less<>; using object_t = ObjectType>>; + AllocatorType::value_type>>; using array_t = ArrayType>; diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 5e53e4f9..dc44c12c 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -496,9 +496,7 @@ class basic_json using object_t = ObjectType - AllocatorType>>; + AllocatorType::value_type>>; /*! @brief a type for an array diff --git a/include/nlohmann/ordered_map.hpp b/include/nlohmann/ordered_map.hpp index 2fa00c0d..756b586a 100644 --- a/include/nlohmann/ordered_map.hpp +++ b/include/nlohmann/ordered_map.hpp @@ -11,8 +11,8 @@ namespace nlohmann /// ordered_map: a minimal map-like container that preserves insertion order /// for use within nlohmann::basic_json template , - class IgnoredAllocator = std::allocator>, - class Container = std::vector>> + class Allocator = std::allocator>, + class Container = std::vector, Allocator>> struct ordered_map : Container { using key_type = Key; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 43da17f5..2d3d31a0 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -15880,8 +15880,8 @@ namespace nlohmann /// ordered_map: a minimal map-like container that preserves insertion order /// for use within nlohmann::basic_json template , - class IgnoredAllocator = std::allocator>, - class Container = std::vector>> + class Allocator = std::allocator>, + class Container = std::vector, Allocator>> struct ordered_map : Container { using key_type = Key; @@ -16348,9 +16348,7 @@ class basic_json using object_t = ObjectType - AllocatorType>>; + AllocatorType::value_type>>; /*! @brief a type for an array