diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index d647d742..797f714d 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -13,9 +13,6 @@ #include // forward_list #include // inserter, front_inserter, end #include // map -#ifdef JSON_HAS_CPP_17 - #include // optional -#endif #include // string #include // tuple, make_tuple #include // is_arithmetic, is_same, is_enum, underlying_type, is_convertible @@ -32,6 +29,11 @@ #include #include +// include after macro_scope.hpp +#ifdef JSON_HAS_CPP_17 + #include // optional +#endif + NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { @@ -47,7 +49,6 @@ inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n) } #ifdef JSON_HAS_CPP_17 -#ifndef JSON_USE_IMPLICIT_CONVERSIONS template void from_json(const BasicJsonType& j, std::optional& opt) { @@ -60,8 +61,6 @@ void from_json(const BasicJsonType& j, std::optional& opt) opt.emplace(j.template get()); } } - -#endif // JSON_USE_IMPLICIT_CONVERSIONS #endif // JSON_HAS_CPP_17 // overloads for basic_json template parameters diff --git a/include/nlohmann/detail/conversions/to_json.hpp b/include/nlohmann/detail/conversions/to_json.hpp index ead45665..f8413850 100644 --- a/include/nlohmann/detail/conversions/to_json.hpp +++ b/include/nlohmann/detail/conversions/to_json.hpp @@ -267,7 +267,7 @@ struct external_constructor #ifdef JSON_HAS_CPP_17 template::value, int> = 0> -void to_json(BasicJsonType& j, const std::optional& opt) +void to_json(BasicJsonType& j, const std::optional& opt) noexcept { if (opt.has_value()) { diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 82d69f7c..53a9ea70 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -173,9 +173,6 @@ #include // forward_list #include // inserter, front_inserter, end #include // map -#ifdef JSON_HAS_CPP_17 - #include // optional -#endif #include // string #include // tuple, make_tuple #include // is_arithmetic, is_same, is_enum, underlying_type, is_convertible @@ -4817,6 +4814,11 @@ NLOHMANN_JSON_NAMESPACE_END // #include +// include after macro_scope.hpp +#ifdef JSON_HAS_CPP_17 + #include // optional +#endif + NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { @@ -4832,7 +4834,6 @@ inline void from_json(const BasicJsonType& j, typename std::nullptr_t& n) } #ifdef JSON_HAS_CPP_17 -#ifndef JSON_USE_IMPLICIT_CONVERSIONS template void from_json(const BasicJsonType& j, std::optional& opt) { @@ -4845,8 +4846,6 @@ void from_json(const BasicJsonType& j, std::optional& opt) opt.emplace(j.template get()); } } - -#endif // JSON_USE_IMPLICIT_CONVERSIONS #endif // JSON_HAS_CPP_17 // overloads for basic_json template parameters @@ -5914,7 +5913,7 @@ struct external_constructor #ifdef JSON_HAS_CPP_17 template::value, int> = 0> -void to_json(BasicJsonType& j, const std::optional& opt) +void to_json(BasicJsonType& j, const std::optional& opt) noexcept { if (opt.has_value()) {