You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Deserializing std::array doesn't compiler (no insert()) #1071
I've found that, at least in Visual Studio (but I suspect everywhere), attempting to convert a JSON into a std::array fails to compile, since std::array has a value type (and therefore uses the container deserializer), but no insert() method (which is used by the container deserializer). While not all that hard to work around, it'd be nice to have it fixed.
auto endpoints = j["endpoints"].get<std::array<glm::vec2, 2>>();
(We already had defined a from_json for glm::vec2, and it was included above.)
The error message (with our own files replaced by descriptions, and ellipses for some of our directory structure, since I'm not sure exactly what is and is not sensitive in that regard, and for some reason some angled brackets aren't showing up):
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.13.26128\include\iterator(107): error C2039: 'insert': is not a member of 'std::array<glm::vec2,2>'
1>{header defining a class that uses the array}(38): note: see declaration of 'std::array<glm::vec2,2>'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.13.26128\include\iterator(106): note: while compiling class template member function 'std::insert_iterator<CompatibleArrayType> &std::insert_iterator<CompatibleArrayType>::operator =(glm::tvec2<float,0> &&)'
1> with
1> [
1> CompatibleArrayType=std::array<glm::vec2,2>
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.13.26128\include\algorithm(1328): note: see reference to function template instantiation 'std::insert_iterator<CompatibleArrayType> &std::insert_iterator<CompatibleArrayType>::operator =(glm::tvec2<float,0> &&)' being compiled
1> with
1> [
1> CompatibleArrayType=std::array<glm::vec2,2>
1> ]
1>c:\...\thirdparty\json\nlohmann_json.hpp(721): note: see reference to class template instantiation 'std::insert_iterator<CompatibleArrayType>' being compiled
1> with
1> [
1> CompatibleArrayType=std::array<glm::vec2,2>
1> ]
1>c:\...\thirdparty\json\nlohmann_json.hpp(766): note: see reference to function template instantiation 'void nlohmann::detail::from_json_array_impl<BasicJsonType,CompatibleArrayType>(const BasicJsonType &,CompatibleArrayType &,nlohmann::detail::priority_tag<0>)' being compiled
1> with
1> [
1> BasicJsonType=nlohmann::json,
1> CompatibleArrayType=std::array<glm::vec2,2>
1> ]
1>c:\...\thirdparty\json\nlohmann_json.hpp(864): note: see reference to function template instantiation 'void nlohmann::detail::from_json<BasicJsonType,T,0>(const BasicJsonType &,CompatibleArrayType &)' being compiled
1> with
1> [
1> BasicJsonType=nlohmann::json,
1> T=std::array<glm::vec2,2>,
1> CompatibleArrayType=std::array<glm::vec2,2>
1> ]
1>c:\...\thirdparty\json\nlohmann_json.hpp(879): note: see reference to function template instantiation 'void nlohmann::detail::from_json_fn::call<BasicJsonType,T>(const BasicJsonType &,T &,nlohmann::detail::priority_tag<1>) noexcept(false) const' being compiled
1> with
1> [
1> BasicJsonType=nlohmann::json,
1> T=std::array<glm::vec2,2>
1> ]
1>c:\...\thirdparty\json\nlohmann_json.hpp(926): note: see reference to function template instantiation 'void nlohmann::detail::from_json_fn::operator ()<_Ty,ValueType>(const BasicJsonType &,T &) noexcept(false) const' being compiled
1> with
1> [
1> _Ty=nlohmann::json,
1> ValueType=std::array<glm::vec2,2>,
1> BasicJsonType=nlohmann::json,
1> T=std::array<glm::vec2,2>
1> ]
1>c:\...\thirdparty\json\nlohmann_json.hpp(3237): note: see reference to function template instantiation 'void nlohmann::adl_serializer<T,void>::from_json<const nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>&,T>(BasicJsonType,ValueType &) noexcept(false)' being compiled
1> with
1> [
1> T=std::array<glm::vec2,2>,
1> BasicJsonType=const nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> &,
1> ValueType=std::array<glm::vec2,2>
1> ]
1>c:\...\thirdparty\json\nlohmann_json.hpp(3237): note: see reference to function template instantiation 'void nlohmann::adl_serializer<T,void>::from_json<const nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>&,T>(BasicJsonType,ValueType &) noexcept(false)' being compiled
1> with
1> [
1> T=std::array<glm::vec2,2>,
1> BasicJsonType=const nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> &,
1> ValueType=std::array<glm::vec2,2>
1> ]
1>{cpp file being compiled}(45): note: see reference to function template instantiation 'ValueType nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get<std::array<glm::vec2,2>,std::array<glm::vec2,2>,0>(void) noexcept(false) const' being compiled
1> with
1> [
1> ValueType=std::array<glm::vec2,2>
1> ]
1>{cpp file being compiled}(45): note: see reference to function template instantiation 'ValueType nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get<std::array<glm::vec2,2>,std::array<glm::vec2,2>,0>(void) noexcept(false) const' being compiled
1> with
1> [
1> ValueType=std::array<glm::vec2,2>
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.13.26128\include\xlocale(446): note: see reference to class template instantiation 'std::basic_string_view<char,std::char_traits<char>>' being compiled
nlohmann::json exampleJSON;
auto exampleOutput = exampleJSON["test"].get<std::array<float, 2>>();
However, I did a bit of experimenting, and found that the version of the library I'm using is a bit out-of-date (or perhaps modified), and this is causing the conflict; if I replace it with the version from master, it works fine. Sorry, I didn't realize the one I was using wasn't up-to-date.
Activity
nlohmann commentedon May 1, 2018
I cannot reproduce the issue. This works with Xcode Version 9.3 (9E145):
What did you try? What was the error message?
Yitzi2 commentedon May 1, 2018
In my from_json for a class, I had the line:
(We already had defined a from_json for glm::vec2, and it was included above.)
The error message (with our own files replaced by descriptions, and ellipses for some of our directory structure, since I'm not sure exactly what is and is not sensitive in that regard, and for some reason some angled brackets aren't showing up):
theodelrieu commentedon May 2, 2018
Could you reproduce the issue with a minimal code snippet?
Yitzi2 commentedon May 2, 2018
Here's my minimal code snippet:
#include <nlohmann_json.hpp>
nlohmann::json exampleJSON;
auto exampleOutput = exampleJSON["test"].get<std::array<float, 2>>();
However, I did a bit of experimenting, and found that the version of the library I'm using is a bit out-of-date (or perhaps modified), and this is causing the conflict; if I replace it with the version from master, it works fine. Sorry, I didn't realize the one I was using wasn't up-to-date.