Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conversion json to std::map doesn't work for types <int, double> #1372

Closed
TheWaveWarden opened this issue Nov 23, 2018 · 3 comments
Closed

Comments

@TheWaveWarden
Copy link

//<int, double> doesn't work
std::map<int, double> map_input3 = {{1, 2.0}};
json json_map3(map_input3);
std::map<int, double> map_output3 = json_map3;

tested on Ubuntu18, compiler is g++, version 3.1.2

as previously discussed in
#600

@TheWaveWarden
Copy link
Author

error message:

/opt/robodev/include/nlohmann/detail/conversions/from_json.hpp: In instantiation of ‘void nlohmann::detail::from_json(const BasicJsonType&, std::pair<_Tp1, _Tp2>&) [with BasicJsonType = nlohmann::basic_json<>; A1 = const int; A2 = double]’:
/opt/robodev/include/nlohmann/detail/conversions/from_json.hpp:288:25:   required from ‘decltype ((nlohmann::detail::from_json(j, val), void())) nlohmann::detail::from_json_fn::call(const BasicJsonType&, T&, nlohmann::detail::priority_tag<1>) const [with BasicJsonType = nlohmann::basic_json<>; T = std::pair<const int, double>; decltype ((nlohmann::detail::from_json(j, val), void())) = void]’
/opt/robodev/include/nlohmann/detail/conversions/from_json.hpp:309:47:   required from ‘void nlohmann::detail::from_json_fn::operator()(const BasicJsonType&, T&) const [with BasicJsonType = nlohmann::basic_json<>; T = std::pair<const int, double>]’
/opt/robodev/include/nlohmann/adl_serializer.hpp:26:30:   required from ‘static void nlohmann::adl_serializer< <template-parameter-1-1>, <template-parameter-1-2> >::from_json(BasicJsonType&&, ValueType&) [with BasicJsonType = const nlohmann::basic_json<>&; ValueType = std::pair<const int, double>; <template-parameter-1-1> = std::pair<const int, double>; <template-parameter-1-2> = void]’
/opt/robodev/include/nlohmann/json.hpp:2570:45:   required from ‘ValueType nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::get() const [with ValueTypeCV = std::pair<const int, double>; ValueType = std::pair<const int, double>; typename std::enable_if<(((! nlohmann::detail::is_basic_json<ValueType>::value) && nlohmann::detail::has_from_json<nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>, ValueType>::value) && (! nlohmann::detail::has_non_default_from_json<nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>, ValueType>::value)), int>::type <anonymous> = 0; 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]’
/opt/robodev/include/nlohmann/detail/conversions/from_json.hpp:150:5:   required from ‘nlohmann::detail::from_json_array_impl(const BasicJsonType&, CompatibleArrayType&, nlohmann::detail::priority_tag<0>)::<lambda(const BasicJsonType&)> [with BasicJsonType = nlohmann::basic_json<>; CompatibleArrayType = std::map<int, double>]’
/opt/robodev/include/nlohmann/detail/conversions/from_json.hpp:145:51:   [ skipping 3 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/opt/robodev/include/nlohmann/detail/conversions/from_json.hpp:288:25:   required from ‘decltype ((nlohmann::detail::from_json(j, val), void())) nlohmann::detail::from_json_fn::call(const BasicJsonType&, T&, nlohmann::detail::priority_tag<1>) const [with BasicJsonType = nlohmann::basic_json<>; T = std::map<int, double>; decltype ((nlohmann::detail::from_json(j, val), void())) = void]’
/opt/robodev/include/nlohmann/detail/conversions/from_json.hpp:309:47:   required from ‘void nlohmann::detail::from_json_fn::operator()(const BasicJsonType&, T&) const [with BasicJsonType = nlohmann::basic_json<>; T = std::map<int, double>]’
/opt/robodev/include/nlohmann/adl_serializer.hpp:26:30:   required from ‘static void nlohmann::adl_serializer< <template-parameter-1-1>, <template-parameter-1-2> >::from_json(BasicJsonType&&, ValueType&) [with BasicJsonType = const nlohmann::basic_json<>&; ValueType = std::map<int, double>; <template-parameter-1-1> = std::map<int, double>; <template-parameter-1-2> = void]’
/opt/robodev/include/nlohmann/json.hpp:2570:45:   required from ‘ValueType nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::get() const [with ValueTypeCV = std::map<int, double>; ValueType = std::map<int, double>; typename std::enable_if<(((! nlohmann::detail::is_basic_json<ValueType>::value) && nlohmann::detail::has_from_json<nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>, ValueType>::value) && (! nlohmann::detail::has_non_default_from_json<nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>, ValueType>::value)), int>::type <anonymous> = 0; 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]’
/opt/robodev/include/nlohmann/json.hpp:2832:30:   required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::operator ValueType() const [with ValueType = std::map<int, double>; typename std::enable_if<(((((! std::is_pointer<_Ptr>::value) && (! std::is_same<ValueType, nlohmann::detail::json_ref<nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer> > >::value)) && (! std::is_same<ValueType, typename StringType::value_type>::value)) && (! nlohmann::detail::is_basic_json<BasicJsonType>::value)) && (! std::is_same<ValueType, std::initializer_list<typename StringType::value_type> >::value)), int>::type <anonymous> = 0; 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]’
/home/frederik_siepe/rd_root/repos/rd_path_planning/src/rd/path_planner/rd_path_planner.cpp:58:38:   required from here
/opt/robodev/include/nlohmann/detail/conversions/from_json.hpp:265:7: error: use of deleted function ‘std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(typename std::conditional<std::__not_<std::__and_<std::is_copy_assignable<_Tp>, std::is_copy_assignable<_T2> > >::value, const std::pair<_T1, _T2>&, const std::__nonesuch_no_braces&>::type) [with _T1 = const int; _T2 = double; typename std::conditional<std::__not_<std::__and_<std::is_copy_assignable<_Tp>, std::is_copy_assignable<_T2> > >::value, const std::pair<_T1, _T2>&, const std::__nonesuch_no_braces&>::type = const std::pair<const int, double>&]’
     p = {j.at(0).template get<A1>(), j.at(1).template get<A2>()};
     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/eigen3/Eigen/Core:80,
                 from /opt/ros/melodic/include/eigen_conversions/eigen_kdl.h:37,
                 from /home/frederik_siepe/rd_root/repos/rd_path_planning/src/rd/path_planner/rd_path_planner.cpp:1:
/usr/include/c++/7/bits/stl_pair.h:378:7: note: declared here
       operator=(typename conditional<

@theodelrieu
Copy link
Contributor

Your code works on my machine with GCC 8.2. Note that your compiler is not supported.

What version of the library are you using?

@TheWaveWarden
Copy link
Author

I'm using json-version version 3.1.2, which seems not to be up to date as well.
Then the error is on my side, my apologies. I will try a newer version and/or supported compiler later and let you know if there are still complications!
Many Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants