Skip to content

Commit

Permalink
📝 fixing documentation #867
Browse files Browse the repository at this point in the history
The example in the documentation on how to "force" an array of arrays was wrong since the first release. Fixed the documentation and added checks for the README unit tests.
  • Loading branch information
nlohmann committed Dec 10, 2017
1 parent 0693945 commit 772bb3c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -160,7 +160,7 @@ json empty_object_implicit = json({});
json empty_object_explicit = json::object();

// a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]]
json array_not_object = { json::array({"currency", "USD"}), json::array({"value", 42.99}) };
json array_not_object = json::array({ {"currency", "USD"}, {"value", 42.99} });
```
Expand Down
12 changes: 6 additions & 6 deletions src/json.hpp
Expand Up @@ -3646,12 +3646,12 @@ class iter_impl

public:

/// The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17.
/// The C++ Standard has never required user-defined iterators to derive from std::iterator.
/// A user-defined iterator should provide publicly accessible typedefs named
/// iterator_category, value_type, difference_type, pointer, and reference.
/// Note that value_type is required to be non-const, even for constant iterators.
using iterator_category = std::bidirectional_iterator_tag;
/// The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17.
/// The C++ Standard has never required user-defined iterators to derive from std::iterator.
/// A user-defined iterator should provide publicly accessible typedefs named
/// iterator_category, value_type, difference_type, pointer, and reference.
/// Note that value_type is required to be non-const, even for constant iterators.
using iterator_category = std::bidirectional_iterator_tag;

/// the type of the values when the iterator is dereferenced
using value_type = typename BasicJsonType::value_type;
Expand Down
9 changes: 8 additions & 1 deletion test/src/unit-readme.cpp
Expand Up @@ -100,13 +100,20 @@ TEST_CASE("README", "[hide]")
{
// ways to express the empty array []
json empty_array_implicit = {{}};
CHECK(empty_array_implicit.is_array());
json empty_array_explicit = json::array();
CHECK(empty_array_explicit.is_array());

// a way to express the empty object {}
json empty_object_explicit = json::object();
CHECK(empty_object_explicit.is_object());

// a way to express an _array_ of key/value pairs [["currency", "USD"], ["value", 42.99]]
json array_not_object = { json::array({"currency", "USD"}), json::array({"value", 42.99}) };
json array_not_object = json::array({ {"currency", "USD"}, {"value", 42.99} });
CHECK(array_not_object.is_array());
CHECK(array_not_object.size() == 2);
CHECK(array_not_object[0].is_array());
CHECK(array_not_object[1].is_array());
}

{
Expand Down

0 comments on commit 772bb3c

Please sign in to comment.