reverting first/second experiment #350

parent 723c8756
...@@ -66,7 +66,7 @@ to the files you want to use JSON objects. That's it. Do not forget to set the n ...@@ -66,7 +66,7 @@ to the files you want to use JSON objects. That's it. Do not forget to set the n
:beer: If you are using OS X and [Homebrew](http://brew.sh), just type `brew tap nlohmann/json` and `brew install nlohmann_json` and you're set. If you want the bleeding edge rather than the latest release, use `brew install nlohmann_json --HEAD`. :beer: If you are using OS X and [Homebrew](http://brew.sh), just type `brew tap nlohmann/json` and `brew install nlohmann_json` and you're set. If you want the bleeding edge rather than the latest release, use `brew install nlohmann_json --HEAD`.
If you are using the Meson Build System, then you can wrap this repo as a subproject. If you are using the [Meson Build System](http://mesonbuild.com), then you can wrap this repo as a subproject.
:warning: [Version 3.0.0](https://github.com/nlohmann/json/wiki/Road-toward-3.0.0) is currently under development. Branch `develop` is used for the ongoing work and is probably **unstable**. Please use the `master` branch for the last stable version 2.1.1. :warning: [Version 3.0.0](https://github.com/nlohmann/json/wiki/Road-toward-3.0.0) is currently under development. Branch `develop` is used for the ongoing work and is probably **unstable**. Please use the `master` branch for the last stable version 2.1.1.
...@@ -839,6 +839,7 @@ I deeply appreciate the help of the following people. ...@@ -839,6 +839,7 @@ I deeply appreciate the help of the following people.
- [ftillier](https://github.com/ftillier) fixed a compiler warning. - [ftillier](https://github.com/ftillier) fixed a compiler warning.
- [tinloaf](https://github.com/tinloaf) made sure all pushed warnings are properly popped. - [tinloaf](https://github.com/tinloaf) made sure all pushed warnings are properly popped.
- [Fytch](https://github.com/Fytch) found a bug in the documentation. - [Fytch](https://github.com/Fytch) found a bug in the documentation.
- [Jay Sistar](https://github.com/Type1J) implemented a Meson build description
Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone. Thanks a lot for helping out! Please [let me know](mailto:mail@nlohmann.me) if I forgot someone.
...@@ -865,7 +866,6 @@ The library itself contains of a single header file licensed under the MIT licen ...@@ -865,7 +866,6 @@ The library itself contains of a single header file licensed under the MIT licen
- [**Github Changelog Generator**](https://github.com/skywinder/github-changelog-generator) to generate the [ChangeLog](https://github.com/nlohmann/json/blob/develop/ChangeLog.md) - [**Github Changelog Generator**](https://github.com/skywinder/github-changelog-generator) to generate the [ChangeLog](https://github.com/nlohmann/json/blob/develop/ChangeLog.md)
- [**libFuzzer**](http://llvm.org/docs/LibFuzzer.html) to implement fuzz testing for OSS-Fuzz - [**libFuzzer**](http://llvm.org/docs/LibFuzzer.html) to implement fuzz testing for OSS-Fuzz
- [**OSS-Fuzz**](https://github.com/google/oss-fuzz) for continuous fuzz testing of the library - [**OSS-Fuzz**](https://github.com/google/oss-fuzz) for continuous fuzz testing of the library
- [**re2c**](http://re2c.org) to generate an automaton for the lexical analysis
- [**send_to_wandbox**](https://github.com/nlohmann/json/blob/develop/doc/scripts/send_to_wandbox.py) to send code examples to [Wandbox](http://melpon.org/wandbox) - [**send_to_wandbox**](https://github.com/nlohmann/json/blob/develop/doc/scripts/send_to_wandbox.py) to send code examples to [Wandbox](http://melpon.org/wandbox)
- [**Travis**](https://travis-ci.org) for [continuous integration](https://travis-ci.org/nlohmann/json) on Linux and macOS - [**Travis**](https://travis-ci.org) for [continuous integration](https://travis-ci.org/nlohmann/json) on Linux and macOS
- [**Valgrind**](http://valgrind.org) to check for correct memory management - [**Valgrind**](http://valgrind.org) to check for correct memory management
......
#include "json.hpp"
using json = nlohmann::json;
int main()
{
// create JSON values
json j_object = {{"one", 1}, {"two", 2}};
json j_array = {1, 2, 4, 8, 16};
// example for an object
for (auto& x : json::iterator_wrapper(j_object))
{
std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
}
// example for an array
for (auto& x : json::iterator_wrapper(j_array))
{
std::cout << "key: " << x.key() << ", value: " << x.value() << '\n';
}
}
<a target="_blank" href="https://wandbox.org/permlink/YkOQK9sqEfbKUF31"><b>online</b></a>
\ No newline at end of file
key: one, value: 1
key: two, value: 2
key: 0, value: 1
key: 1, value: 2
key: 2, value: 4
key: 3, value: 8
key: 4, value: 16
...@@ -5204,6 +5204,8 @@ class basic_json ...@@ -5204,6 +5204,8 @@ class basic_json
reference to the JSON values is returned, so there is no access to the reference to the JSON values is returned, so there is no access to the
underlying iterator. underlying iterator.
@liveexample{The following code shows how the wrapper is used,iterator_wrapper}
@note The name of this function is not yet final and may change in the @note The name of this function is not yet final and may change in the
future. future.
*/ */
...@@ -7877,80 +7879,6 @@ class basic_json ...@@ -7877,80 +7879,6 @@ class basic_json
class iteration_proxy class iteration_proxy
{ {
private: private:
/// helper class for first "property"
template<typename ProxyType>
class iterator_key_property
{
private:
/// the reference to the proxy
ProxyType& proxy;
public:
explicit iterator_key_property(ProxyType& proxyRef) noexcept
: proxy(proxyRef) {}
/// conversion operator (calls key())
operator typename basic_json::string_t() const
{
return proxy.key();
}
/// equal operator (calls key())
template<typename KeyType>
bool operator==(const KeyType& key) const
{
return proxy.key() == key;
}
/// not equal operator (calls key())
template<typename KeyType>
bool operator!=(const KeyType& key) const
{
return proxy.key() != key;
}
};
/// helper class for second "property"
template<typename ProxyType>
class iterator_value_property
{
private:
/// the reference to the proxy
ProxyType& proxy;
public:
explicit iterator_value_property(ProxyType& proxyRef) noexcept
: proxy(proxyRef) {}
/// conversion operator (calls value())
operator typename IteratorType::reference() const
{
return proxy.value();
}
/// equal operator (calls value())
template<typename ValueType>
bool operator==(const ValueType& value) const
{
return proxy.value() == value;
}
/// not equal operator (calls value())
template<typename ValueType>
bool operator!=(const ValueType& value) const
{
return proxy.value() != value;
}
/// assignment operator (calls value())
template<typename ValueType>
iterator_value_property<ProxyType>& operator=(const ValueType& value)
{
proxy.value() = value;
return *this;
}
};
/// helper class for iteration /// helper class for iteration
class iteration_proxy_internal class iteration_proxy_internal
{ {
...@@ -7961,11 +7889,8 @@ class basic_json ...@@ -7961,11 +7889,8 @@ class basic_json
size_t array_index = 0; size_t array_index = 0;
public: public:
iterator_key_property<iteration_proxy_internal> first;
iterator_value_property<iteration_proxy_internal> second;
explicit iteration_proxy_internal(IteratorType it) noexcept explicit iteration_proxy_internal(IteratorType it) noexcept
: anchor(it), first(*this), second(*this) : anchor(it)
{} {}
/// dereference operator (needed for range-based for) /// dereference operator (needed for range-based for)
......
...@@ -30,7 +30,6 @@ add_executable(${JSON_UNITTEST_TARGET_NAME} ...@@ -30,7 +30,6 @@ add_executable(${JSON_UNITTEST_TARGET_NAME}
"src/unit-element_access2.cpp" "src/unit-element_access2.cpp"
"src/unit-inspection.cpp" "src/unit-inspection.cpp"
"src/unit-iterator_wrapper.cpp" "src/unit-iterator_wrapper.cpp"
"src/unit-iterator_wrapper_first_second.cpp"
"src/unit-iterators1.cpp" "src/unit-iterators1.cpp"
"src/unit-iterators2.cpp" "src/unit-iterators2.cpp"
"src/unit-json_patch.cpp" "src/unit-json_patch.cpp"
......
...@@ -34,6 +34,8 @@ using nlohmann::json; ...@@ -34,6 +34,8 @@ using nlohmann::json;
#include <fstream> #include <fstream>
void check_utf8string(bool success_expected, int byte1, int byte2, int byte3, int byte4);
// create and check a JSON string with up to four UTF-8 bytes // create and check a JSON string with up to four UTF-8 bytes
void check_utf8string(bool success_expected, int byte1, int byte2 = -1, int byte3 = -1, int byte4 = -1) void check_utf8string(bool success_expected, int byte1, int byte2 = -1, int byte3 = -1, int byte4 = -1)
{ {
......
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