Skip to content

Commit ddf0a45

Browse files
author
gatopeich
committed
Use AllocatorType<ObjectType::value_type>,
instead of hard-coding it for std::map's value_type
1 parent 15337b2 commit ddf0a45

File tree

6 files changed

+10
-12
lines changed

6 files changed

+10
-12
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ cmake-build-debug
2626

2727
test/test-*
2828
test/test_data.hpp
29+
Temporary
30+
2931
/.vs
3032
.vscode
3133

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ This library will not support comments in the future. If you wish to use comment
15271527
15281528
### Order of object keys
15291529
1530-
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)).
1530+
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)).
15311531
15321532
### Memory Release
15331533

doc/mkdocs/docs/features/types.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ From the template arguments, the following types are derived:
8989
```cpp
9090
using object_comparator_t = std::less<>;
9191
using object_t = ObjectType<StringType, basic_json, object_comparator_t,
92-
AllocatorType<std::pair<const StringType, basic_json>>>;
92+
AllocatorType<typename ObjectType<StringType, basic_json>::value_type>>;
9393

9494
using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
9595

include/nlohmann/json.hpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,7 @@ class basic_json
496496
using object_t = ObjectType<StringType,
497497
basic_json,
498498
object_comparator_t,
499-
// TODO: AllocatorType<ObjectType::value_type>
500-
AllocatorType<std::pair<const StringType,
501-
basic_json>>>;
499+
AllocatorType<typename ObjectType<StringType, basic_json>::value_type>>;
502500

503501
/*!
504502
@brief a type for an array

include/nlohmann/ordered_map.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace nlohmann
1111
/// ordered_map: a minimal map-like container that preserves insertion order
1212
/// for use within nlohmann::basic_json<ordered_map>
1313
template <class Key, class T, class IgnoredLess = std::less<Key>,
14-
class IgnoredAllocator = std::allocator<std::pair<Key, T>>,
15-
class Container = std::vector<std::pair<Key, T>>>
14+
class Allocator = std::allocator<std::pair<Key, T>>,
15+
class Container = std::vector<std::pair<Key, T>, Allocator>>
1616
struct ordered_map : Container
1717
{
1818
using key_type = Key;

single_include/nlohmann/json.hpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -15880,8 +15880,8 @@ namespace nlohmann
1588015880
/// ordered_map: a minimal map-like container that preserves insertion order
1588115881
/// for use within nlohmann::basic_json<ordered_map>
1588215882
template <class Key, class T, class IgnoredLess = std::less<Key>,
15883-
class IgnoredAllocator = std::allocator<std::pair<Key, T>>,
15884-
class Container = std::vector<std::pair<Key, T>>>
15883+
class Allocator = std::allocator<std::pair<Key, T>>,
15884+
class Container = std::vector<std::pair<Key, T>, Allocator>>
1588515885
struct ordered_map : Container
1588615886
{
1588715887
using key_type = Key;
@@ -16348,9 +16348,7 @@ class basic_json
1634816348
using object_t = ObjectType<StringType,
1634916349
basic_json,
1635016350
object_comparator_t,
16351-
// TODO: AllocatorType<ObjectType::value_type>
16352-
AllocatorType<std::pair<const StringType,
16353-
basic_json>>>;
16351+
AllocatorType<typename ObjectType<StringType, basic_json>::value_type>>;
1635416352

1635516353
/*!
1635616354
@brief a type for an array

0 commit comments

Comments
 (0)