mapbox / geojson-cpp

A C++14 library for converting GeoJSON into geometry.hpp representation
ISC License
66 stars 27 forks source link

MSVC 2017: Error C2440 #36

Open thomasreiser opened 5 years ago

thomasreiser commented 5 years ago

When trying to compile geojson_impl.hpp with Visual Studio 2017 (64 bit), I am getting the following errors:

screenshot from 2019-02-24 13-00-39


1>mapbox/geojson_impl.hpp(113): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>mapbox/geojson_impl.hpp(115): error C2440: 'return': cannot convert from 'bool' to 'mapbox::feature::value'
1>mapbox/geojson_impl.hpp(115): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>mapbox/geojson_impl.hpp(117): error C2440: 'return': cannot convert from 'bool' to 'mapbox::feature::value'
1>mapbox/geojson_impl.hpp(117): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>mapbox/geojson_impl.hpp(119): error C2440: 'return': cannot convert from 'mapbox::geojson::prop_map' to 'mapbox::feature::value'
1>mapbox/geojson_impl.hpp(119): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>mapbox/geojson_impl.hpp(121): error C2440: 'return': cannot convert from 'Cont' to 'mapbox::feature::value'
1>        with
1>        [
1>            Cont=std::vector<mapbox::feature::value,std::allocator<mapbox::feature::value>>
1>        ]
1>mapbox/geojson_impl.hpp(121): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>mapbox/geojson_impl.hpp(123): error C2440: 'return': cannot convert from 'std::string' to 'mapbox::feature::value'
1>mapbox/geojson_impl.hpp(123): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>mapbox/geojson_impl.hpp(127): error C2440: 'return': cannot convert from 'uint64_t' to 'mapbox::feature::value'
1>mapbox/geojson_impl.hpp(127): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>mapbox/geojson_impl.hpp(129): error C2440: 'return': cannot convert from 'int64_t' to 'mapbox::feature::value'
1>mapbox/geojson_impl.hpp(129): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>mapbox/geojson_impl.hpp(130): error C2440: 'return': cannot convert from 'double' to 'mapbox::feature::value'
1>mapbox/geojson_impl.hpp(130): note: No constructor could take the source type, or constructor overload resolution was ambiguous```
dpmcmlxxvi commented 5 years ago

Same error also present in MSVC 2019.

nedieon commented 4 years ago

I haven't fully tested it yet, but I modified the code for it to compile and run:

template <>
value convert<value>(const rapidjson_value &json) {
    struct mapbox::feature::value newValue;

    switch (json.GetType()) {
    case rapidjson::kNullType:
        newValue.set<mapbox::feature::null_value_t>();
        return newValue;
    case rapidjson::kFalseType:
        newValue.set<bool>(false);
        return newValue;
    case rapidjson::kTrueType:
        newValue.set<bool>(true);
        return newValue;
    case rapidjson::kObjectType:
        newValue.set<std::unordered_map<std::string, value>>(convert<prop_map>(json));
        return newValue;
    case rapidjson::kArrayType:
        newValue.set<std::vector<value>>(convert<std::vector<value>>(json));
        return newValue;
    case rapidjson::kStringType:
        newValue.set<std::string>(std::string(json.GetString(), json.GetStringLength()));
        return newValue;
    default:
        assert(json.GetType() == rapidjson::kNumberType);
        if (json.IsUint64()) {
            newValue.set<std::uint64_t>(json.GetUint64());
            return newValue;
        }
        if (json.IsInt64()) {
            newValue.set<std::uint64_t>(json.GetInt64());
            return newValue;
        }
        newValue.set<std::double_t>(json.GetDouble());
        return newValue;
    } 
}

from

template <>
value convert<value>(const rapidjson_value &json) {
    switch (json.GetType()) {
    case rapidjson::kNullType:
        return null_value_t{};
    case rapidjson::kFalseType:
        return false;
    case rapidjson::kTrueType:
        return true;
    case rapidjson::kObjectType:
        return convert<prop_map>(json);
    case rapidjson::kArrayType:
        return convert<std::vector<value>>(json);
    case rapidjson::kStringType:
        return std::string(json.GetString(), json.GetStringLength());
    default:
        assert(json.GetType() == rapidjson::kNumberType);
        if (json.IsUint64())
            return std::uint64_t(json.GetUint64());
        if (json.IsInt64())
            return std::int64_t(json.GetInt64());
        return json.GetDouble();
    }
}