mirror of
https://github.com/nlohmann/json.git
synced 2025-07-28 12:02:00 +03:00
Move UDLs out of the global namespace (#3605)
* Move UDLs into nlohmann::literals::json_literals namespace * Add 'using namespace' to unit tests * Add 'using namespace' to examples * Add 'using namespace' to README * Move UDL mkdocs pages out of basic_json/ * Update documentation * Update docset index * Add JSON_GlobalUDLs CMake option * Add unit test * Build examples without global UDLs * Add CI target
This commit is contained in:
committed by
GitHub
parent
8fd8b52907
commit
9aafcbe965
@ -5074,6 +5074,29 @@ std::string to_string(const NLOHMANN_BASIC_JSON_TPL& j)
|
||||
return j.dump();
|
||||
}
|
||||
|
||||
inline namespace literals
|
||||
{
|
||||
inline namespace json_literals
|
||||
{
|
||||
|
||||
/// @brief user-defined string literal for JSON values
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
inline nlohmann::json operator "" _json(const char* s, std::size_t n)
|
||||
{
|
||||
return nlohmann::json::parse(s, s + n);
|
||||
}
|
||||
|
||||
/// @brief user-defined string literal for JSON pointer
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
|
||||
{
|
||||
return nlohmann::json::json_pointer(std::string(s, n));
|
||||
}
|
||||
|
||||
} // namespace json_literals
|
||||
} // namespace literals
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
///////////////////////
|
||||
@ -5130,21 +5153,9 @@ inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC
|
||||
|
||||
} // namespace std
|
||||
|
||||
/// @brief user-defined string literal for JSON values
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
inline nlohmann::json operator "" _json(const char* s, std::size_t n)
|
||||
{
|
||||
return nlohmann::json::parse(s, s + n);
|
||||
}
|
||||
|
||||
/// @brief user-defined string literal for JSON pointer
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/
|
||||
JSON_HEDLEY_NON_NULL(1)
|
||||
inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
|
||||
{
|
||||
return nlohmann::json::json_pointer(std::string(s, n));
|
||||
}
|
||||
#if JSON_USE_GLOBAL_UDLS
|
||||
using namespace nlohmann::literals::json_literals; // NOLINT(build/namespaces_literals)
|
||||
#endif
|
||||
|
||||
#include <nlohmann/detail/macro_unscope.hpp>
|
||||
|
||||
|
Reference in New Issue
Block a user