Add versioned, ABI-tagged inline namespace and namespace macros (#3590)

* Add versioned inline namespace

Add a versioned inline namespace to prevent ABI issues when linking code
using multiple library versions.

* Add namespace macros

* Encode ABI information in inline namespace

Add _diag suffix to inline namespace if JSON_DIAGNOSTICS is enabled, and
_ldvcmp suffix if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON is enabled.

* Move ABI-affecting macros into abi_macros.hpp

* Move std_fs namespace definition into std_fs.hpp

* Remove std_fs namespace from unit test

* Format more files in tests directory

* Add unit tests

* Update documentation

* Fix GDB pretty printer

* fixup! Add namespace macros

* Derive ABI prefix from NLOHMANN_JSON_VERSION_*
This commit is contained in:
Florian Albrechtskirchinger authored and GitHub committed 2022-07-30 21:59:13 +02:00
1 parent fca1ddda96
commit d909f80960
72 files changed
+23116 -561

No files matched your search

@@ -10,7 +10,8 @@
#include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann
{
NLOHMANN_JSON_NAMESPACE_BEGIN
NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin);
} // namespace nlohmann
NLOHMANN_JSON_NAMESPACE_END
@@ -10,7 +10,8 @@
#include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann
{
NLOHMANN_JSON_NAMESPACE_BEGIN
NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end);
} // namespace nlohmann
NLOHMANN_JSON_NAMESPACE_END
+2 -3
View File
@@ -15,8 +15,7 @@
#include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann
{
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
@@ -164,4 +163,4 @@ struct static_const
#endif
} // namespace detail
} // namespace nlohmann
NLOHMANN_JSON_NAMESPACE_END
+5 -4
View File
@@ -12,11 +12,11 @@
#include <nlohmann/detail/meta/void_t.hpp>
// https://en.cppreference.com/w/cpp/experimental/is_detected
namespace nlohmann
{
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
// https://en.cppreference.com/w/cpp/experimental/is_detected
struct nonesuch
{
nonesuch() = delete;
@@ -65,5 +65,6 @@ using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
template<class To, template<class...> class Op, class... Args>
using is_detected_convertible =
std::is_convertible<detected_t<Op, Args...>, To>;
} // namespace detail
} // namespace nlohmann
NLOHMANN_JSON_NAMESPACE_END
@@ -8,11 +8,14 @@
#pragma once
namespace nlohmann
{
#include <nlohmann/detail/abi_macros.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
// dispatching helper struct
template <class T> struct identity_tag {};
} // namespace detail
} // namespace nlohmann
NLOHMANN_JSON_NAMESPACE_END
+5 -3
View File
@@ -12,13 +12,14 @@
#include <utility> // declval
#include <string> // string
#include <nlohmann/detail/abi_macros.hpp>
#include <nlohmann/detail/meta/detected.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
namespace nlohmann
{
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
template<typename T>
using null_function_t = decltype(std::declval<T&>().null());
@@ -153,5 +154,6 @@ struct is_sax_static_asserts
"Missing/invalid function: bool parse_error(std::size_t, const "
"std::string&, const exception&)");
};
} // namespace detail
} // namespace nlohmann
NLOHMANN_JSON_NAMESPACE_END
+21
View File
@@ -0,0 +1,21 @@
#pragma once
#include <nlohmann/detail/macro_scope.hpp>
#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
#include <experimental/filesystem>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
namespace std_fs = std::experimental::filesystem;
} // namespace detail
NLOHMANN_JSON_NAMESPACE_END
#elif JSON_HAS_FILESYSTEM
#include <filesystem>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
namespace std_fs = std::filesystem;
} // namespace detail
NLOHMANN_JSON_NAMESPACE_END
#endif
+4 -5
View File
@@ -13,17 +13,15 @@
#include <utility> // declval
#include <tuple> // tuple
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/iterators/iterator_traits.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/call_std/begin.hpp>
#include <nlohmann/detail/meta/call_std/end.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/detected.hpp>
#include <nlohmann/json_fwd.hpp>
namespace nlohmann
{
NLOHMANN_JSON_NAMESPACE_BEGIN
/*!
@brief detail namespace with internal helper functions
@@ -34,6 +32,7 @@ implementations of some @ref basic_json methods, and meta-programming helpers.
*/
namespace detail
{
/////////////
// helpers //
/////////////
@@ -686,4 +685,4 @@ inline constexpr bool value_in_range_of(T val)
}
} // namespace detail
} // namespace nlohmann
NLOHMANN_JSON_NAMESPACE_END
+7 -4
View File
@@ -8,14 +8,17 @@
#pragma once
namespace nlohmann
{
#include <nlohmann/detail/abi_macros.hpp>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
template<typename ...Ts> struct make_void
{
using type = void;
};
template<typename ...Ts> using void_t = typename make_void<Ts...>::type;
} // namespace detail
} // namespace nlohmann
} // namespace detail
NLOHMANN_JSON_NAMESPACE_END