From ce0b3fe5a334567825a554a08b76c725d0790500 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 21 Jan 2017 16:12:17 +0100 Subject: [PATCH] :construction: made type_name() public --- doc/examples/type_name.cpp | 24 ++++++++++++++++++++++++ doc/examples/type_name.link | 1 + doc/examples/type_name.output | 7 +++++++ src/json.hpp | 5 ++++- src/json.hpp.re2c | 5 ++++- 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 doc/examples/type_name.cpp create mode 100644 doc/examples/type_name.link create mode 100644 doc/examples/type_name.output diff --git a/doc/examples/type_name.cpp b/doc/examples/type_name.cpp new file mode 100644 index 00000000..815e92d7 --- /dev/null +++ b/doc/examples/type_name.cpp @@ -0,0 +1,24 @@ +#include + +using json = nlohmann::json; + +int main() +{ + // create JSON values + json j_null; + json j_boolean = true; + json j_number_integer = 17; + json j_number_float = 23.42; + json j_object = {{"one", 1}, {"two", 2}}; + json j_array = {1, 2, 4, 8, 16}; + json j_string = "Hello, world"; + + // call type_name() + std::cout << j_null.type_name() << '\n'; + std::cout << j_boolean.type_name() << '\n'; + std::cout << j_number_integer.type_name() << '\n'; + std::cout << j_number_float.type_name() << '\n'; + std::cout << j_object.type_name() << '\n'; + std::cout << j_array.type_name() << '\n'; + std::cout << j_string.type_name() << '\n'; +} diff --git a/doc/examples/type_name.link b/doc/examples/type_name.link new file mode 100644 index 00000000..39d1f973 --- /dev/null +++ b/doc/examples/type_name.link @@ -0,0 +1 @@ +online \ No newline at end of file diff --git a/doc/examples/type_name.output b/doc/examples/type_name.output new file mode 100644 index 00000000..ad906a49 --- /dev/null +++ b/doc/examples/type_name.output @@ -0,0 +1,7 @@ +null +boolean +number +number +object +array +string diff --git a/src/json.hpp b/src/json.hpp index fa9b85f2..2c1fd658 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -7767,7 +7767,6 @@ class basic_json /// @} - private: /////////////////////////// // convenience functions // /////////////////////////// @@ -7782,6 +7781,9 @@ class basic_json @complexity Constant. + @liveexample{The following code exemplifies `type_name()` for all JSON + types.,typename} + @since version 1.0.0 */ std::string type_name() const @@ -7805,6 +7807,7 @@ class basic_json } } + private: /*! @brief calculates the extra space to escape a JSON string diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 886b9dde..f552a390 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -7767,7 +7767,6 @@ class basic_json /// @} - private: /////////////////////////// // convenience functions // /////////////////////////// @@ -7782,6 +7781,9 @@ class basic_json @complexity Constant. + @liveexample{The following code exemplifies `type_name()` for all JSON + types.,typename} + @since version 1.0.0 */ std::string type_name() const @@ -7805,6 +7807,7 @@ class basic_json } } + private: /*! @brief calculates the extra space to escape a JSON string