Skip to content
This repository was archived by the owner on Mar 26, 2020. It is now read-only.
This repository was archived by the owner on Mar 26, 2020. It is now read-only.

MSVC12 Compatibility #2

@PaulFreund

Description

@PaulFreund

I really like the library design and would like to use it cross platform. Unfortunately there are a few roadblocks for using it with MSVC12 (VS2013):

  • In json11.cpp the Statics struct can't be initialized because not every member has an initializer
  • Missing noexcept and snprintf
  • The templates that should define implicit constructors for map and vector like objects seem to fail because std::declval() can not be properly resolved and therefore begin can't be found

The first one can be easily fixed by removing the initializers and adding them to the initializer-list in statics():

struct Statics {
    const std::shared_ptr<JsonValue> null;
    const std::shared_ptr<JsonValue> t;
    const std::shared_ptr<JsonValue> f;
    const string empty_string;
    const vector<Json> empty_vector;
    const map<string, Json> empty_map;
};

const Statics & statics() {
    static const Statics s {
        make_shared<JsonNull>(),
        make_shared<JsonBoolean>(true),
        make_shared<JsonBoolean>(false),
        "",
        vector<Json>(),
        map<string, Json>()
    };
    return s;
}

The missing noexcept and sprintf are a bit harder. MSVC12 does not (yet) include them. It is possible to create a preprocessor define for noexcept after the STL header includes (as an error is thrown when trying to define the missing noexcept myself). snprintf can be replaced by _snprintf but unfortunately behaves a bit different (snprintf truncates and always 0-terminates, _snprintf does not 0-terminate if the buffer is too small, also the return values are different which are not used anyway).

I didn't invest enough much time digging in c++11s templating features to understand the third problem yet. A simple solution is to comment out the two constructors but I am sure there is a better solution.

This is an issue for me and I don't know if you are interested in supporting MSVC12 (don't know if this gets better with the next compiler update).

PS: Having this library header only would be really nice too, but that's secondary for now

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions