diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index 5c79a67e5..207d3e302 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -19,21 +19,19 @@ #include #include -#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL -#if JSON_STD_FILESYSTEM_EXPERIMENTAL +#if JSON_HAS_EXPERIMENTAL_FILESYSTEM #include namespace nlohmann::detail { namespace std_fs = std::experimental::filesystem; } // namespace nlohmann::detail -#else +#elif JSON_HAS_FILESYSTEM #include namespace nlohmann::detail { namespace std_fs = std::filesystem; } // namespace nlohmann::detail #endif -#endif namespace nlohmann { @@ -460,7 +458,7 @@ void from_json(const BasicJsonType& j, std::unordered_map void from_json(const BasicJsonType& j, std_fs::path& p) { diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index 7fc5a05ef..7628ae011 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -15,21 +15,19 @@ #include #include -#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL -#if JSON_STD_FILESYSTEM_EXPERIMENTAL +#if JSON_HAS_EXPERIMENTAL_FILESYSTEM #include namespace nlohmann::detail { namespace std_fs = std::experimental::filesystem; } // namespace nlohmann::detail -#else +#elif JSON_HAS_FILESYSTEM #include namespace nlohmann::detail { namespace std_fs = std::filesystem; } // namespace nlohmann::detail #endif -#endif namespace nlohmann { @@ -403,7 +401,7 @@ void to_json(BasicJsonType& j, const T& t) to_json_tuple_impl(j, t, make_index_sequence::value> {}); } -#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL +#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM template void to_json(BasicJsonType& j, const std_fs::path& p) { diff --git a/include/nlohmann/detail/macro_scope.hpp b/include/nlohmann/detail/macro_scope.hpp index e113ea573..00f197b63 100644 --- a/include/nlohmann/detail/macro_scope.hpp +++ b/include/nlohmann/detail/macro_scope.hpp @@ -38,27 +38,33 @@ #endif #ifdef JSON_HAS_CPP_17 - // set JSON_STD_FILESYSTEM_EXPERIMENTAL to 1 if should be taken instead of #if defined(__cpp_lib_filesystem) - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 0 + #define JSON_HAS_FILESYSTEM 1 #elif defined(__cpp_lib_experimental_filesystem) - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 1 + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #elif !defined(__has_include) - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 1 + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #elif __has_include() - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 0 + #define JSON_HAS_FILESYSTEM 1 #elif __has_include() - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 1 - #else - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 0 + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #endif // std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/ #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8 - #undef JSON_STD_FILESYSTEM_EXPERIMENTAL + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #endif #endif +#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0 +#endif + +#ifndef JSON_HAS_FILESYSTEM + #define JSON_HAS_FILESYSTEM 0 +#endif + // disable documentation warnings on clang #if defined(__clang__) #pragma clang diagnostic push diff --git a/include/nlohmann/detail/macro_unscope.hpp b/include/nlohmann/detail/macro_unscope.hpp index e0cc5dc40..1a29fb5e0 100644 --- a/include/nlohmann/detail/macro_unscope.hpp +++ b/include/nlohmann/detail/macro_unscope.hpp @@ -16,7 +16,8 @@ #undef JSON_HAS_CPP_14 #undef JSON_HAS_CPP_17 #undef JSON_HAS_CPP_20 -#undef JSON_STD_FILESYSTEM_EXPERIMENTAL +#undef JSON_HAS_FILESYSTEM +#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION #undef NLOHMANN_BASIC_JSON_TPL #undef JSON_EXPLICIT diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 4cb0056e5..ae187d1fd 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -2326,27 +2326,33 @@ using is_detected_convertible = #endif #ifdef JSON_HAS_CPP_17 - // set JSON_STD_FILESYSTEM_EXPERIMENTAL to 1 if should be taken instead of #if defined(__cpp_lib_filesystem) - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 0 + #define JSON_HAS_FILESYSTEM 1 #elif defined(__cpp_lib_experimental_filesystem) - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 1 + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #elif !defined(__has_include) - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 1 + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #elif __has_include() - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 0 + #define JSON_HAS_FILESYSTEM 1 #elif __has_include() - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 1 - #else - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 0 + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #endif // std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/ #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8 - #undef JSON_STD_FILESYSTEM_EXPERIMENTAL + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #endif #endif +#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0 +#endif + +#ifndef JSON_HAS_FILESYSTEM + #define JSON_HAS_FILESYSTEM 0 +#endif + // disable documentation warnings on clang #if defined(__clang__) #pragma clang diagnostic push @@ -3972,21 +3978,19 @@ T conditional_static_cast(U value) // #include -#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL -#if JSON_STD_FILESYSTEM_EXPERIMENTAL +#if JSON_HAS_EXPERIMENTAL_FILESYSTEM #include namespace nlohmann::detail { namespace std_fs = std::experimental::filesystem; } // namespace nlohmann::detail -#else +#elif JSON_HAS_FILESYSTEM #include namespace nlohmann::detail { namespace std_fs = std::filesystem; } // namespace nlohmann::detail #endif -#endif namespace nlohmann { @@ -4413,7 +4417,7 @@ void from_json(const BasicJsonType& j, std::unordered_map void from_json(const BasicJsonType& j, std_fs::path& p) { @@ -4660,21 +4664,19 @@ class tuple_element> // #include -#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL -#if JSON_STD_FILESYSTEM_EXPERIMENTAL +#if JSON_HAS_EXPERIMENTAL_FILESYSTEM #include namespace nlohmann::detail { namespace std_fs = std::experimental::filesystem; } // namespace nlohmann::detail -#else +#elif JSON_HAS_FILESYSTEM #include namespace nlohmann::detail { namespace std_fs = std::filesystem; } // namespace nlohmann::detail #endif -#endif namespace nlohmann { @@ -5048,7 +5050,7 @@ void to_json(BasicJsonType& j, const T& t) to_json_tuple_impl(j, t, make_index_sequence::value> {}); } -#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL +#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM template void to_json(BasicJsonType& j, const std_fs::path& p) { @@ -26637,7 +26639,8 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std #undef JSON_HAS_CPP_14 #undef JSON_HAS_CPP_17 #undef JSON_HAS_CPP_20 -#undef JSON_STD_FILESYSTEM_EXPERIMENTAL +#undef JSON_HAS_FILESYSTEM +#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION #undef NLOHMANN_BASIC_JSON_TPL #undef JSON_EXPLICIT diff --git a/test/src/unit-regression2.cpp b/test/src/unit-regression2.cpp index 292f5f04a..fa0ca3a0e 100644 --- a/test/src/unit-regression2.cpp +++ b/test/src/unit-regression2.cpp @@ -49,42 +49,40 @@ using ordered_json = nlohmann::ordered_json; #ifdef JSON_HAS_CPP_17 #include -// set JSON_STD_FILESYSTEM_EXPERIMENTAL to 1 if should be taken instead of -#if defined(__cpp_lib_filesystem) - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 0 -#elif defined(__cpp_lib_experimental_filesystem) - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 1 -#elif !defined(__has_include) - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 1 -#elif __has_include() - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 0 -#elif __has_include() - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 1 -#else - #define JSON_STD_FILESYSTEM_EXPERIMENTAL 0 +#ifdef JSON_HAS_CPP_17 + #if defined(__cpp_lib_filesystem) + #define JSON_HAS_FILESYSTEM 1 + #elif defined(__cpp_lib_experimental_filesystem) + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #elif !defined(__has_include) + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #elif __has_include() + #define JSON_HAS_FILESYSTEM 1 + #elif __has_include() + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #endif // std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/ #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8 - #undef JSON_STD_FILESYSTEM_EXPERIMENTAL + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #endif #endif -#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL -#if JSON_STD_FILESYSTEM_EXPERIMENTAL +#if JSON_HAS_EXPERIMENTAL_FILESYSTEM #include namespace nlohmann::detail { namespace std_fs = std::experimental::filesystem; } // namespace nlohmann::detail -#else +#elif JSON_HAS_FILESYSTEM #include namespace nlohmann::detail { namespace std_fs = std::filesystem; } // namespace nlohmann::detail #endif -#endif -#endif + #ifdef JSON_HAS_CPP_20 #include @@ -761,7 +759,7 @@ TEST_CASE("regression tests 2") CHECK(j == k); } -#ifdef JSON_STD_FILESYSTEM_EXPERIMENTAL +#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM SECTION("issue #3070 - Version 3.10.3 breaks backward-compatibility with 3.10.2 ") { nlohmann::detail::std_fs::path text_path("/tmp/text.txt");