Description
I tried to use std::optional with the library. I am using CMake, and, in my CMakeLists.txt, I set the language standard to C++23 with set(CMAKE_CXX_STANDARD 23).
When trying to read a JSON field as std::optional<std::string>>, I get a compilation error that no matching overload could be found.
By skimming over the source code, I could not find any checks for JSON_HAS_CPP_17 in the implementation of the get method.
Reproduction steps
Reading a JSON field as std::optional<T> with json.get<std::optional<T>>.
Expected vs. actual results
Expected
The get method should be able to return std::optional<T>.
Actual
Compiler cannot find a matching overload when using std::optional<T> as template parameter of get.
Minimal code example
nlohmann::json json;
json.get<std::optional<std::string>>();
Error messages
error C2672: 'nlohmann::json_abi_v3_12_0::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::json_abi_v3_12_0::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>,void>::get': no matching overloaded function found
Compiler and operating system
MSVC 19.44.35213.0 & Windows 11
Library version
3.12.0
Validation
Description
I tried to use
std::optionalwith the library. I am using CMake, and, in my CMakeLists.txt, I set the language standard to C++23 withset(CMAKE_CXX_STANDARD 23).When trying to read a JSON field as
std::optional<std::string>>, I get a compilation error that no matching overload could be found.By skimming over the source code, I could not find any checks for
JSON_HAS_CPP_17in the implementation of thegetmethod.Reproduction steps
Reading a JSON field as
std::optional<T>withjson.get<std::optional<T>>.Expected vs. actual results
Expected
The
getmethod should be able to returnstd::optional<T>.Actual
Compiler cannot find a matching overload when using
std::optional<T>as template parameter ofget.Minimal code example
Error messages
Compiler and operating system
MSVC 19.44.35213.0 & Windows 11
Library version
3.12.0
Validation
developbranch is used.