diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index cadc6438e..e4551d1ba 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -13,9 +13,6 @@ #include // tuple #include // false_type, is_constructible, is_integral, is_same, true_type #include // declval -#if defined(__cpp_lib_optional) && __cpp_lib_optional >= 201606L - #include // optional -#endif #if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L #include // byte #endif @@ -80,15 +77,6 @@ struct is_json_ref : std::false_type {}; template struct is_json_ref> : std::true_type {}; -// trait to detect std::optional specializations -template -struct is_std_optional : std::false_type {}; - -#if defined(__cpp_lib_optional) && __cpp_lib_optional >= 201606L -template -struct is_std_optional> : std::true_type {}; -#endif - ////////////////////////// // aliases for detected // ////////////////////////// diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index c9de854c5..ff6fdb087 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -86,6 +86,21 @@ */ NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ +// Trait to detect std::optional specializations. It is defined here rather +// than in type_traits.hpp so that adding the include does not change +// the include order of the C++20 module's global module fragment (the include +// is already pulled in by the conversion headers above); see src/modules/json.cppm. +template +struct is_std_optional : std::false_type {}; + +#ifdef JSON_HAS_CPP_17 +template +struct is_std_optional> : std::true_type {}; +#endif +} // namespace detail + /*! @brief a class to store JSON values diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 98725173f..e8d98cbdb 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3570,9 +3570,6 @@ NLOHMANN_JSON_NAMESPACE_END #include // tuple #include // false_type, is_constructible, is_integral, is_same, true_type #include // declval -#if defined(__cpp_lib_optional) && __cpp_lib_optional >= 201606L - #include // optional -#endif #if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L #include // byte #endif @@ -3820,15 +3817,6 @@ struct is_json_ref : std::false_type {}; template struct is_json_ref> : std::true_type {}; -// trait to detect std::optional specializations -template -struct is_std_optional : std::false_type {}; - -#if defined(__cpp_lib_optional) && __cpp_lib_optional >= 201606L -template -struct is_std_optional> : std::true_type {}; -#endif - ////////////////////////// // aliases for detected // ////////////////////////// @@ -20607,6 +20595,21 @@ NLOHMANN_JSON_NAMESPACE_END */ NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ +// Trait to detect std::optional specializations. It is defined here rather +// than in type_traits.hpp so that adding the include does not change +// the include order of the C++20 module's global module fragment (the include +// is already pulled in by the conversion headers above); see src/modules/json.cppm. +template +struct is_std_optional : std::false_type {}; + +#ifdef JSON_HAS_CPP_17 +template +struct is_std_optional> : std::true_type {}; +#endif +} // namespace detail + /*! @brief a class to store JSON values