Skip to content

error: no matching function for call to ‘nlohmann::basic_json<>::value(int, std::set<int>&)’ #2671

@leonardltk

Description

@leonardltk

Hi, i have a hashmap that i want to serialize/deserialize to/from JSON.
here is my code snippet:

#include <iostream>
#include "nlohmann/json.hpp"
#include <unordered_map>
#include <set>
using namespace std;

using json = nlohmann::json;

int main(){

    unordered_map <int, set<int>> shash;
    shash[3] = { 1 };
    shash[3].insert(33);
    shash[4] = { 44 };
    /*
    shash = {
        3 : {1,33},
        4 : {44},
    }
    */

    json jdEmployees = shash;

    set<int> nullSet;
    nullSet.insert(0);
    set<int> ValueSet = jdEmployees.value(3, nullSet);

    return 0;
}

I compiled it like this:

g++ -o ./debug.out -std=c++11 test.cpp nlohmann/json.hpp && ./debug.out

However i get this error:

test.cpp: In function ‘int main()’:
test.cpp:26:53: error: no matching function for call to ‘nlohmann::basic_json<>::value(int, std::set<int>&)’
     set<int> ValueSet = jdEmployees.value(3, nullSet);
                                                         ^
In file included from test.cpp:2:0:
nlohmann/json.hpp:20279:15: note: candidate: template<class ValueType, typename std::enable_if<(nlohmann::detail::is_getable<nlohmann::basic_json<>, ValueType>::value && (! std::is_same<nlohmann::detail::value_t, ValueType>::value)), int>::type <anonymous> > ValueType nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::value(const typename nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::object_t::key_type&, const ValueType&) const [with ValueType = ValueType; typename std::enable_if<(nlohmann::detail::is_getable<nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>, ValueType>::value && (! std::is_same<nlohmann::detail::value_t, ValueType>::value)), int>::type <anonymous> = <enumerator>; ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; BinaryType = std::vector<unsigned char>]
     ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const
               ^
nlohmann/json.hpp:20279:15: note:   template argument deduction/substitution failed:
test.cpp:50:57: note:   cannot convert ‘3’ (type ‘int’) to type ‘const key_type& {aka const std::__cxx11::basic_string<char>&}’
         set<int> ValueSet = jdEmployees.value(3, nullSet);
                                                         ^
In file included from test.cpp:2:0:
nlohmann/json.hpp:20301:14: note: candidate: nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::value(const typename nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::object_t::key_type&, const char*) const [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; BinaryType = std::vector<unsigned char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::string_t = std::__cxx11::basic_string<char>; typename nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::object_t::key_type = std::__cxx11::basic_string<char>]
     string_t value(const typename object_t::key_type& key, const char* default_value) const
              ^
nlohmann/json.hpp:20301:14: note:   no known conversion for argument 1 from ‘int’ to ‘const key_type& {aka const std::__cxx11::basic_string<char>&}’
nlohmann/json.hpp:20351:15: note: candidate: template<class ValueType, typename std::enable_if<nlohmann::detail::is_getable<nlohmann::basic_json<>, ValueType>::value, int>::type <anonymous> > ValueType nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::value(const json_pointer&, const ValueType&) const [with ValueType = ValueType; typename std::enable_if<nlohmann::detail::is_getable<nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>, ValueType>::value, int>::type <anonymous> = <enumerator>; ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; BinaryType = std::vector<unsigned char>]
     ValueType value(const json_pointer& ptr, const ValueType& default_value) const
               ^
nlohmann/json.hpp:20351:15: note:   template argument deduction/substitution failed:
test.cpp:50:57: note:   cannot convert ‘3’ (type ‘int’) to type ‘const json_pointer& {aka const nlohmann::json_pointer<nlohmann::basic_json<> >&}’
         set<int> ValueSet = jdEmployees.value(3, nullSet);
                                                         ^
In file included from test.cpp:2:0:
nlohmann/json.hpp:20375:14: note: candidate: nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::string_t nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::value(const json_pointer&, const char*) const [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; BinaryType = std::vector<unsigned char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::string_t = std::__cxx11::basic_string<char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::json_pointer = nlohmann::json_pointer<nlohmann::basic_json<> >]
     string_t value(const json_pointer& ptr, const char* default_value) const
              ^
nlohmann/json.hpp:20375:14: note:   no known conversion for argument 1 from ‘int’ to ‘const json_pointer& {aka const nlohmann::json_pointer<nlohmann::basic_json<> >&}’

Metadata

Metadata

Assignees

No one assigned

    Labels

    state: needs more infothe author of the issue needs to provide more details

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions