mirror of
https://github.com/nlohmann/json.git
synced 2024-11-23 22:19:02 +08:00
Use AllocatorType<ObjectType::value_type>,
instead of hard-coding it for std::map's value_type
This commit is contained in:
parent
15337b2cc3
commit
ddf0a45abb
2
.gitignore
vendored
2
.gitignore
vendored
@ -26,6 +26,8 @@ cmake-build-debug
|
||||
|
||||
test/test-*
|
||||
test/test_data.hpp
|
||||
Temporary
|
||||
|
||||
/.vs
|
||||
.vscode
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -89,7 +89,7 @@ From the template arguments, the following types are derived:
|
||||
```cpp
|
||||
using object_comparator_t = std::less<>;
|
||||
using object_t = ObjectType<StringType, basic_json, object_comparator_t,
|
||||
AllocatorType<std::pair<const StringType, basic_json>>>;
|
||||
AllocatorType<typename ObjectType<StringType, basic_json>::value_type>>;
|
||||
|
||||
using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
|
||||
|
||||
|
@ -496,9 +496,7 @@ class basic_json
|
||||
using object_t = ObjectType<StringType,
|
||||
basic_json,
|
||||
object_comparator_t,
|
||||
// TODO: AllocatorType<ObjectType::value_type>
|
||||
AllocatorType<std::pair<const StringType,
|
||||
basic_json>>>;
|
||||
AllocatorType<typename ObjectType<StringType, basic_json>::value_type>>;
|
||||
|
||||
/*!
|
||||
@brief a type for an array
|
||||
|
@ -11,8 +11,8 @@ namespace nlohmann
|
||||
/// ordered_map: a minimal map-like container that preserves insertion order
|
||||
/// for use within nlohmann::basic_json<ordered_map>
|
||||
template <class Key, class T, class IgnoredLess = std::less<Key>,
|
||||
class IgnoredAllocator = std::allocator<std::pair<Key, T>>,
|
||||
class Container = std::vector<std::pair<Key, T>>>
|
||||
class Allocator = std::allocator<std::pair<Key, T>>,
|
||||
class Container = std::vector<std::pair<Key, T>, Allocator>>
|
||||
struct ordered_map : Container
|
||||
{
|
||||
using key_type = Key;
|
||||
|
@ -15880,8 +15880,8 @@ namespace nlohmann
|
||||
/// ordered_map: a minimal map-like container that preserves insertion order
|
||||
/// for use within nlohmann::basic_json<ordered_map>
|
||||
template <class Key, class T, class IgnoredLess = std::less<Key>,
|
||||
class IgnoredAllocator = std::allocator<std::pair<Key, T>>,
|
||||
class Container = std::vector<std::pair<Key, T>>>
|
||||
class Allocator = std::allocator<std::pair<Key, T>>,
|
||||
class Container = std::vector<std::pair<Key, T>, Allocator>>
|
||||
struct ordered_map : Container
|
||||
{
|
||||
using key_type = Key;
|
||||
@ -16348,9 +16348,7 @@ class basic_json
|
||||
using object_t = ObjectType<StringType,
|
||||
basic_json,
|
||||
object_comparator_t,
|
||||
// TODO: AllocatorType<ObjectType::value_type>
|
||||
AllocatorType<std::pair<const StringType,
|
||||
basic_json>>>;
|
||||
AllocatorType<typename ObjectType<StringType, basic_json>::value_type>>;
|
||||
|
||||
/*!
|
||||
@brief a type for an array
|
||||
|
Loading…
Reference in New Issue
Block a user