🔧 add namespaces

This commit is contained in:
Niels Lohmann 2021-11-07 13:13:37 +01:00
parent 5a5073dd2b
commit e97c93f451
No known key found for this signature in database
GPG Key ID: 7F3CEA63AE251B69
152 changed files with 275 additions and 153 deletions

View File

@ -0,0 +1,43 @@
#include <iostream>
#include <nlohmann/json.hpp>
// simple output function
template<typename Map>
void output(const char* prefix, const Map& m)
{
std::cout << prefix << " = { ";
for (auto& element : m)
{
std::cout << element.first << ":" << element.second << ' ';
}
std::cout << "}" << std::endl;
}
int main()
{
// create and fill two maps
nlohmann::ordered_map<std::string, std::string> m_ordered;
m_ordered["one"] = "eins";
m_ordered["two"] = "zwei";
m_ordered["three"] = "drei";
std::map<std::string, std::string> m_std;
m_std["one"] = "eins";
m_std["two"] = "zwei";
m_std["three"] = "drei";
// output: m_ordered is ordered by insertion order, m_std is ordered by key
output("m_ordered", m_ordered);
output("m_std", m_std);
// erase and re-add "one" key
m_ordered.erase("one");
m_ordered["one"] = "eins";
m_std.erase("one");
m_std["one"] = "eins";
// output: m_ordered shows newly added key at the end; m_std is again ordered by key
output("m_ordered", m_ordered);
output("m_std", m_std);
}

View File

@ -0,0 +1,4 @@
m_ordered = { one:eins two:zwei three:drei }
m_std = { one:eins three:drei two:zwei }
m_ordered = { two:zwei three:drei one:eins }
m_std = { one:eins three:drei two:zwei }

18
doc/examples/std_hash.cpp Normal file
View File

@ -0,0 +1,18 @@
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
int main()
{
std::cout << "hash(null) = " << std::hash<json> {}(json(nullptr)) << '\n'
<< "hash(false) = " << std::hash<json> {}(json(false)) << '\n'
<< "hash(0) = " << std::hash<json> {}(json(0)) << '\n'
<< "hash(0U) = " << std::hash<json> {}(json(0U)) << '\n'
<< "hash(\"\") = " << std::hash<json> {}(json("")) << '\n'
<< "hash({}) = " << std::hash<json> {}(json::object()) << '\n'
<< "hash([]) = " << std::hash<json> {}(json::array()) << '\n'
<< "hash({\"hello\": \"world\"}) = " << std::hash<json> {}("{\"hello\": \"world\"}"_json)
<< std::endl;
}

View File

@ -0,0 +1,8 @@
hash(null) = 2654435769
hash(false) = 2654436030
hash(0) = 2654436095
hash(0U) = 2654436156
hash("") = 11160318156688833227
hash({}) = 2654435832
hash([]) = 2654435899
hash({"hello": "world"}) = 3701319991624763853

View File

@ -1,4 +1,4 @@
# adl_serializer::from_json
# <small>nlohmann::adl_serializer::</small>from_json
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# adl_serializer
# <small>nlohmann::</small>adl_serializer
```cpp
template<typename, typename>

View File

@ -1,4 +1,4 @@
# adl_serializer::to_json
# <small>nlohmann::adl_serializer::</small>to_json
```cpp
template<typename BasicJsonType, typename TargetType = ValueType>

View File

@ -1,4 +1,4 @@
# basic_json::accept
# <small>nlohmann::basic_json::</small>accept
```cpp
// (1)
@ -84,6 +84,11 @@ Linear in the length of the input. The parser is a predictive LL(1) parser.
--8<-- "examples/accept__string.output"
```
## See also
- [parse](parse.md) - deserialize from a compatible input
- [operator>>](operator_gtgt.md) - deserialize from stream
## Version history
- Added in version 3.0.0.

View File

@ -1,4 +1,4 @@
# basic_json::array
# <small>nlohmann::basic_json::</small>array
```cpp
static basic_json array(initializer_list_t init = {});

View File

@ -1,4 +1,4 @@
# basic_json::array_t
# <small>nlohmann::basic_json::</small>array_t
```cpp
using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;

View File

@ -1,4 +1,4 @@
# basic_json::at
# <small>nlohmann::basic_json::</small>at
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::back
# <small>nlohmann::basic_json::</small>back
```cpp
reference back();

View File

@ -1,4 +1,4 @@
# basic_json::basic_json
# <small>nlohmann::basic_json::</small>basic_json
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::begin
# <small>nlohmann::basic_json::</small>begin
```cpp
iterator begin() noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::binary
# <small>nlohmann::basic_json::</small>binary
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::binary_t
# <small>nlohmann::basic_json::</small>binary_t
```cpp
using binary_t = byte_container_with_subtype<BinaryType>;

View File

@ -1,4 +1,4 @@
# basic_json::boolean_t
# <small>nlohmann::basic_json::</small>boolean_t
```cpp
using boolean_t = BooleanType;

View File

@ -1,4 +1,4 @@
# basic_json::cbegin
# <small>nlohmann::basic_json::</small>cbegin
```cpp
const_iterator cbegin() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::cbor_tag_handler_t
# <small>nlohmann::basic_json::</small>cbor_tag_handler_t
```cpp
enum class cbor_tag_handler_t

View File

@ -1,4 +1,4 @@
# basic_json::cend
# <small>nlohmann::basic_json::</small>cend
```cpp
const_iterator cend() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::clear
# <small>nlohmann::basic_json::</small>clear
```cpp
void clear() noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::contains
# <small>nlohmann::basic_json::</small>contains
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::count
# <small>nlohmann::basic_json::</small>count
```cpp
template<typename KeyT>

View File

@ -1,4 +1,4 @@
# basic_json::crbegin
# <small>nlohmann::basic_json::</small>crbegin
```cpp
const_reverse_iterator crbegin() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::crend
# <small>nlohmann::basic_json::</small>crend
```cpp
const_reverse_iterator crend() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::diff
# <small>nlohmann::basic_json::</small>diff
```cpp
static basic_json diff(const basic_json& source,

View File

@ -1,4 +1,4 @@
# basic_json::dump
# <small>nlohmann::basic_json::</small>dump
```cpp
string_t dump(const int indent = -1,

View File

@ -1,4 +1,4 @@
# basic_json::emplace
# <small>nlohmann::basic_json::</small>emplace
```cpp
template<class... Args>

View File

@ -1,4 +1,4 @@
# basic_json::emplace_back
# <small>nlohmann::basic_json::</small>emplace_back
```cpp
template<class... Args>

View File

@ -1,4 +1,4 @@
# basic_json::empty
# <small>nlohmann::basic_json::</small>empty
```cpp
bool empty() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::end
# <small>nlohmann::basic_json::</small>end
```cpp
iterator end() noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::erase
# <small>nlohmann::basic_json::</small>erase
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::error_handler_t
# <small>nlohmann::basic_json::</small>error_handler_t
```cpp
enum class error_handler_t {

View File

@ -1,4 +1,4 @@
# basic_json::exception
# <small>nlohmann::basic_json::</small>exception
```cpp
class exception : public std::exception;

View File

@ -1,4 +1,4 @@
# basic_json::find
# <small>nlohmann::basic_json::</small>find
```cpp
template<typename KeyT>

View File

@ -1,4 +1,4 @@
# basic_json::flatten
# <small>nlohmann::basic_json::</small>flatten
```cpp
basic_json flatten() const;

View File

@ -1,4 +1,4 @@
# basic_json::from_bson
# <small>nlohmann::basic_json::</small>from_bson
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::from_cbor
# <small>nlohmann::basic_json::</small>from_cbor
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::from_msgpack
# <small>nlohmann::basic_json::</small>from_msgpack
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::from_ubjson
# <small>nlohmann::basic_json::</small>from_ubjson
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::front
# <small>nlohmann::basic_json::</small>front
```cpp
reference front();

View File

@ -1,4 +1,4 @@
# basic_json::get
# <small>nlohmann::basic_json::</small>get
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::get_allocator
# <small>nlohmann::basic_json::</small>get_allocator
```cpp
static allocator_type get_allocator();

View File

@ -1,4 +1,4 @@
# basic_json::get_binary
# <small>nlohmann::basic_json::</small>get_binary
```cpp
binary_t& get_binary();

View File

@ -1,4 +1,4 @@
# basic_json::get_ptr
# <small>nlohmann::basic_json::</small>get_ptr
```cpp
template<typename PointerType>

View File

@ -1,4 +1,4 @@
# basic_json::get_ref
# <small>nlohmann::basic_json::</small>get_ref
```cpp
template<typename ReferenceType>

View File

@ -1,4 +1,4 @@
# basic_json::get_to
# <small>nlohmann::basic_json::</small>get_to
```cpp
template<typename ValueType>

View File

@ -1,6 +1,6 @@
# basic_json
# <small>nlohmann::</small>basic_json
Defined in header `<json.hpp>`
<small>Defined in header `<nlohmann/json.hpp>`</small>
```cpp
template<

View File

@ -1,4 +1,4 @@
# basic_json::input_format_t
# <small>nlohmann::basic_json::</small>input_format_t
```cpp
enum class input_format_t {

View File

@ -1,4 +1,4 @@
# basic_json::insert
# <small>nlohmann::basic_json::</small>insert
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::invalid_iterator
# <small>nlohmann::basic_json::</small>invalid_iterator
```cpp
class invalid_iterator : public exception;

View File

@ -1,4 +1,4 @@
# basic_json::is_array
# <small>nlohmann::basic_json::</small>is_array
```cpp
constexpr bool is_array() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_binary
# <small>nlohmann::basic_json::</small>is_binary
```cpp
constexpr bool is_binary() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_boolean
# <small>nlohmann::basic_json::</small>is_boolean
```cpp
constexpr bool is_boolean() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_discarded
# <small>nlohmann::basic_json::</small>is_discarded
```cpp
constexpr bool is_discarded() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_null
# <small>nlohmann::basic_json::</small>is_null
```cpp
constexpr bool is_null() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_number
# <small>nlohmann::basic_json::</small>is_number
```cpp
constexpr bool is_number() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_number_float
# <small>nlohmann::basic_json::</small>is_number_float
```cpp
constexpr bool is_number_float() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_number_integer
# <small>nlohmann::basic_json::</small>is_number_integer
```cpp
constexpr bool is_number_integer() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_number_unsigned
# <small>nlohmann::basic_json::</small>is_number_unsigned
```cpp
constexpr bool is_number_unsigned() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_object
# <small>nlohmann::basic_json::</small>is_object
```cpp
constexpr bool is_object() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_primitive
# <small>nlohmann::basic_json::</small>is_primitive
```cpp
constexpr bool is_primitive() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_string
# <small>nlohmann::basic_json::</small>is_string
```cpp
constexpr bool is_string() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::is_structured
# <small>nlohmann::basic_json::</small>is_structured
```cpp
constexpr bool is_structured() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::items
# <small>nlohmann::basic_json::</small>items
```cpp
iteration_proxy<iterator> items() noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::json_serializer
# <small>nlohmann::basic_json::</small>json_serializer
```cpp
template<typename T, typename SFINAE>

View File

@ -1,4 +1,4 @@
# basic_json::max_size
# <small>nlohmann::basic_json::</small>max_size
```cpp
size_type max_size() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::merge_patch
# <small>nlohmann::basic_json::</small>merge_patch
```cpp
void merge_patch(const basic_json& apply_patch);

View File

@ -1,4 +1,4 @@
# basic_json::meta
# <small>nlohmann::basic_json::</small>meta
```cpp
static basic_json meta();

View File

@ -1,4 +1,4 @@
# basic_json::number_float_t
# <small>nlohmann::basic_json::</small>number_float_t
```cpp
using number_float_t = NumberFloatType;

View File

@ -1,4 +1,4 @@
# basic_json::number_integer_t
# <small>nlohmann::basic_json::</small>number_integer_t
```cpp
using number_integer_t = NumberIntegerType;

View File

@ -1,4 +1,4 @@
# basic_json::number_unsigned_t
# <small>nlohmann::basic_json::</small>number_unsigned_t
```cpp
using number_unsigned_t = NumberUnsignedType;

View File

@ -1,4 +1,4 @@
# basic_json::object
# <small>nlohmann::basic_json::</small>object
```cpp
static basic_json object(initializer_list_t init = {});

View File

@ -1,4 +1,4 @@
# basic_json::object_comparator_t
# <small>nlohmann::basic_json::</small>object_comparator_t
```cpp
using object_comparator_t = std::less<StringType>; // until C++14

View File

@ -1,4 +1,4 @@
# basic_json::object_t
# <small>nlohmann::basic_json::</small>object_t
```cpp
using object_t = ObjectType<StringType,

View File

@ -1,4 +1,4 @@
# basic_json::operator+=
# <small>nlohmann::basic_json::</small>operator+=
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::operator=
# <small>nlohmann::basic_json::</small>operator=
```cpp
basic_json& operator=(basic_json other) noexcept (

View File

@ -1,4 +1,4 @@
# basic_json::operator[]
# <small>nlohmann::basic_json::</small>operator[]
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::operator ValueType
# <small>nlohmann::basic_json::</small>operator ValueType
```cpp
template<typename ValueType>

View File

@ -1,4 +1,4 @@
# basic_json::operator==
# <small>nlohmann::basic_json::</small>operator==
```cpp
bool operator==(const_reference lhs, const_reference rhs) noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::operator>=
# <small>nlohmann::basic_json::</small>operator>=
```cpp
bool operator>=(const_reference lhs, const_reference rhs) noexcept,

View File

@ -1,4 +1,4 @@
# basic_json::operator>
# <small>nlohmann::basic_json::</small>operator>
```cpp
bool operator>(const_reference lhs, const_reference rhs) noexcept,

View File

@ -51,7 +51,8 @@ A UTF-8 byte order mark is silently ignored.
## See also
- [parse](parse.md) for a variant with a parser callback function to filter values while parsing
- [accept](accept.md) - check if the input is valid JSON
- [parse](parse.md) - deserialize from a compatible input
## Version history

View File

@ -1,4 +1,4 @@
# basic_json::operator<=
# <small>nlohmann::basic_json::</small>operator<=
```cpp
bool operator<=(const_reference lhs, const_reference rhs) noexcept,

View File

@ -1,4 +1,4 @@
# basic_json::operator""_json
# <small>nlohmann::basic_json::</small>operator""_json
```cpp
json operator "" _json(const char* s, std::size_t n);

View File

@ -1,4 +1,4 @@
# basic_json::operator""_json_pointer
# <small>nlohmann::basic_json::</small>operator""_json_pointer
```cpp
json_pointer operator "" _json_pointer(const char* s, std::size_t n);

View File

@ -1,4 +1,4 @@
# basic_json::operator<
# <small>nlohmann::basic_json::</small>operator<
```cpp
bool operator<(const_reference lhs, const_reference rhs) noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::operator!=
# <small>nlohmann::basic_json::</small>operator!=
```cpp
bool operator!=(const_reference lhs, const_reference rhs) noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::operator value_t
# <small>nlohmann::basic_json::</small>operator value_t
```cpp
constexpr operator value_t() const noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::other_error
# <small>nlohmann::basic_json::</small>other_error
```cpp
class other_error : public exception;

View File

@ -1,4 +1,4 @@
# basic_json::out_of_range
# <small>nlohmann::basic_json::</small>out_of_range
```cpp
class out_of_range : public exception;

View File

@ -1,4 +1,4 @@
# basic_json::parse
# <small>nlohmann::basic_json::</small>parse
```cpp
// (1)
@ -180,6 +180,11 @@ super-linear complexity.
--8<-- "examples/parse__allow_exceptions.output"
```
## See also
- [accept](accept.md) - check if the input is valid JSON
- [operator>>](operator_gtgt.md) - deserialize from stream
## Version history
- Added in version 1.0.0.

View File

@ -1,4 +1,4 @@
# basic_json::parse_error
# <small>nlohmann::basic_json::</small>parse_error
```cpp
class parse_error : public exception;

View File

@ -1,4 +1,4 @@
# basic_json::parse_event_t
# <small>nlohmann::basic_json::</small>parse_event_t
```cpp
enum class parse_event_t : std::uint8_t {

View File

@ -1,4 +1,4 @@
# basic_json::parser_callback_t
# <small>nlohmann::basic_json::</small>parser_callback_t
```cpp
template<typename BasicJsonType>

View File

@ -1,4 +1,4 @@
# basic_json::patch
# <small>nlohmann::basic_json::</small>patch
```cpp
basic_json patch(const basic_json& json_patch) const;

View File

@ -1,4 +1,4 @@
# basic_json::push_back
# <small>nlohmann::basic_json::</small>push_back
```cpp
// (1)

View File

@ -1,4 +1,4 @@
# basic_json::rbegin
# <small>nlohmann::basic_json::</small>rbegin
```cpp
reverse_iterator rbegin() noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::rend
# <small>nlohmann::basic_json::</small>rend
```cpp
reverse_iterator rend() noexcept;

View File

@ -1,4 +1,4 @@
# basic_json::sax_parse
# <small>nlohmann::basic_json::</small>sax_parse
```cpp
// (1)

Some files were not shown because too many files have changed in this diff Show More