Commit ddf0a45a by gatopeich

Use AllocatorType<ObjectType::value_type>,

instead of hard-coding it for std::map's value_type
parent 15337b2c
...@@ -26,6 +26,8 @@ cmake-build-debug ...@@ -26,6 +26,8 @@ cmake-build-debug
test/test-* test/test-*
test/test_data.hpp test/test_data.hpp
Temporary
/.vs /.vs
.vscode .vscode
......
...@@ -1527,7 +1527,7 @@ This library will not support comments in the future. If you wish to use comment ...@@ -1527,7 +1527,7 @@ This library will not support comments in the future. If you wish to use comment
### Order of object keys ### 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 ### Memory Release
......
...@@ -89,7 +89,7 @@ From the template arguments, the following types are derived: ...@@ -89,7 +89,7 @@ From the template arguments, the following types are derived:
```cpp ```cpp
using object_comparator_t = std::less<>; using object_comparator_t = std::less<>;
using object_t = ObjectType<StringType, basic_json, object_comparator_t, 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>>; using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
......
...@@ -496,9 +496,7 @@ class basic_json ...@@ -496,9 +496,7 @@ class basic_json
using object_t = ObjectType<StringType, using object_t = ObjectType<StringType,
basic_json, basic_json,
object_comparator_t, object_comparator_t,
// TODO: AllocatorType<ObjectType::value_type> AllocatorType<typename ObjectType<StringType, basic_json>::value_type>>;
AllocatorType<std::pair<const StringType,
basic_json>>>;
/*! /*!
@brief a type for an array @brief a type for an array
......
...@@ -11,8 +11,8 @@ namespace nlohmann ...@@ -11,8 +11,8 @@ namespace nlohmann
/// ordered_map: a minimal map-like container that preserves insertion order /// ordered_map: a minimal map-like container that preserves insertion order
/// for use within nlohmann::basic_json<ordered_map> /// for use within nlohmann::basic_json<ordered_map>
template <class Key, class T, class IgnoredLess = std::less<Key>, template <class Key, class T, class IgnoredLess = std::less<Key>,
class IgnoredAllocator = std::allocator<std::pair<Key, T>>, class Allocator = std::allocator<std::pair<Key, T>>,
class Container = std::vector<std::pair<Key, T>>> class Container = std::vector<std::pair<Key, T>, Allocator>>
struct ordered_map : Container struct ordered_map : Container
{ {
using key_type = Key; using key_type = Key;
......
...@@ -15880,8 +15880,8 @@ namespace nlohmann ...@@ -15880,8 +15880,8 @@ namespace nlohmann
/// ordered_map: a minimal map-like container that preserves insertion order /// ordered_map: a minimal map-like container that preserves insertion order
/// for use within nlohmann::basic_json<ordered_map> /// for use within nlohmann::basic_json<ordered_map>
template <class Key, class T, class IgnoredLess = std::less<Key>, template <class Key, class T, class IgnoredLess = std::less<Key>,
class IgnoredAllocator = std::allocator<std::pair<Key, T>>, class Allocator = std::allocator<std::pair<Key, T>>,
class Container = std::vector<std::pair<Key, T>>> class Container = std::vector<std::pair<Key, T>, Allocator>>
struct ordered_map : Container struct ordered_map : Container
{ {
using key_type = Key; using key_type = Key;
...@@ -16348,9 +16348,7 @@ class basic_json ...@@ -16348,9 +16348,7 @@ class basic_json
using object_t = ObjectType<StringType, using object_t = ObjectType<StringType,
basic_json, basic_json,
object_comparator_t, object_comparator_t,
// TODO: AllocatorType<ObjectType::value_type> AllocatorType<typename ObjectType<StringType, basic_json>::value_type>>;
AllocatorType<std::pair<const StringType,
basic_json>>>;
/*! /*!
@brief a type for an array @brief a type for an array
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment