- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 7.2k
 
Open
Labels
kind: bugstate: needs more infothe author of the issue needs to provide more detailsthe author of the issue needs to provide more details
Description
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 foundCompiler and operating system
MSVC 19.44.35213.0 & Windows 11
Library version
3.12.0
Validation
-  The bug also occurs if the latest version from the 
developbranch is used. - I can successfully compile and run the unit tests. #4865
 
cacharle and zhuangyan-stone
Metadata
Metadata
Assignees
Labels
kind: bugstate: needs more infothe author of the issue needs to provide more detailsthe author of the issue needs to provide more details