json: ::get() fails in new(er) release [MSVC]

Compiler: MSVC 15.1 (2017) with VS2015 libraries etc.

Was working with: c42273d (2.1.1)

    hsv_t(const json &values)
        : hsv_t( 
            wrap360( values[0].get<int>()),
            clamp100(values[1].get<int>()),
            clamp100(values[2].get<int>()),
            clamp100(values[3].get<int>())){}

Fails with: d300a8e (2.1.1) latest dev

Replaced with:
    hsv_t(const json &values)
        : hsv_t( 
            wrap360( static_cast<int>(values[0])),
            clamp100(static_cast<int>(values[1])),
            clamp100(static_cast<int>(values[2])),
            clamp100(static_cast<int>(values[3]))){}

But error just moved to json.hpp +9836

    template < typename ValueType, typename std::enable_if <
                   not std::is_pointer<ValueType>::value and
                   not std::is_same<ValueType, detail::json_ref<basic_json>>::value and
                   not std::is_same<ValueType, typename string_t::value_type>::value
#ifndef _MSC_VER  // fix for issue #167 operator<< ambiguity under VS2015
                   and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
#endif
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_MSC_VER) && _MSC_VER >1900 && defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
                   and not std::is_same<ValueType, typename std::string_view>::value
#endif
                   , int >::type = 0 >
    operator ValueType() const
    {
        // delegate the call to get<>() const
        return get<ValueType>();
    }
1>E:\git\infamous-dll\src\vendor\sfinktah\include\json.hpp(9836): error C2672: 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get': no matching overloaded function found
1>e:\git\infamous-dll\src\Update/Types.h(333): note: see reference to function template instantiation 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::operator ValueType(void) const<float,0>' being compiled
1>        with
1>        [
1>            ValueType=float
1>        ]
1>e:\git\infamous-dll\src\Update/Types.h(333): note: see reference to function template instantiation 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::operator ValueType(void) const<float,0>' being compiled
1>        with
1>        [
1>            ValueType=float
1>        ]
1>E:\git\infamous-dll\src\vendor\sfinktah\include\json.hpp(9836): error C2783: 'const PointerType nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get(void) noexcept const': could not deduce template argument for '__formal'
1>E:\git\infamous-dll\src\vendor\sfinktah\include\json.hpp(9663): note: see declaration of 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get'
1>E:\git\infamous-dll\src\vendor\sfinktah\include\json.hpp(9836): error C2783: 'PointerType nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get(void) noexcept': could not deduce template argument for '__formal'
1>E:\git\infamous-dll\src\vendor\sfinktah\include\json.hpp(9651): note: see declaration of 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get'
1>E:\git\infamous-dll\src\vendor\sfinktah\include\json.hpp(9836): error C2783: 'ValueType nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get(void) noexcept(<expr>) const': could not deduce template argument for '__formal'
1>E:\git\infamous-dll\src\vendor\sfinktah\include\json.hpp(9614): note: see declaration of 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get'
1>E:\git\infamous-dll\src\vendor\sfinktah\include\json.hpp(9836): error C2783: 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer> nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get(void) const': could not deduce template argument for '__formal'
1>E:\git\infamous-dll\src\vendor\sfinktah\include\json.hpp(9509): note: see declaration of 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::get'

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (10 by maintainers)

Most upvoted comments

I don’t know if that will help, but you really should not add free functions in the nlohmann namespace.

Could you put the from/to_json in the quicktype namespace, just above TestSchema’s definition?

Thanks, @theodelrieu – that did indeed solve my problem. I misunderstood the docs about where the to_json / from_json functions should live, and it looks like the code generation tool I was using made the same error.