Merge branch 'develop' into feature/exceptions_3.0.0

This commit is contained in:
Niels Lohmann 2017-03-12 11:51:24 +01:00
commit 89f6068385
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
7 changed files with 116 additions and 8 deletions

View file

@ -585,10 +585,11 @@ TEST_CASE("modifiers")
SECTION("insert nothing (count = 0)")
{
auto pos = j_array.end();
auto it = j_array.insert(j_array.end(), 0, 5);
CHECK(j_array.size() == 4);
CHECK(it == pos);
// the returned iterator points to the first inserted element;
// there were 4 elements, so it should point to the 5th
CHECK(it == j_array.begin() + 4);
CHECK(j_array == json({1, 2, 3, 4}));
}
}

View file

@ -833,4 +833,20 @@ TEST_CASE("regression tests")
std::string s2 = j2.dump();
CHECK(s1 == s2);
}
SECTION("issue #486 - json::value_t can't be a map's key type in VC++ 2015")
{
// the code below must compile with MSVC
std::map<json::value_t, std::string> jsonTypes ;
jsonTypes[json::value_t::array] = "array";
}
SECTION("issue #494 - conversion from vector<bool> to json fails to build")
{
std::vector<bool> boolVector = {false, true, false, false};
json j;
j["bool_vector"] = boolVector;
CHECK(j["bool_vector"].dump() == "[false,true,false,false]");
}
}

View file

@ -49,16 +49,19 @@ enum class country
struct age
{
int m_val;
age(int rhs = 0) : m_val(rhs) {}
};
struct name
{
std::string m_val;
name(const std::string rhs = "") : m_val(rhs) {}
};
struct address
{
std::string m_val;
address(const std::string rhs = "") : m_val(rhs) {}
};
struct person
@ -66,18 +69,24 @@ struct person
age m_age;
name m_name;
country m_country;
person() : m_age(), m_name(), m_country() {}
person(const age& a, const name& n, const country& c) : m_age(a), m_name(n), m_country(c) {}
};
struct contact
{
person m_person;
address m_address;
contact() : m_person(), m_address() {}
contact(const person& p, const address& a) : m_person(p), m_address(a) {}
};
struct contact_book
{
name m_book_name;
std::vector<contact> m_contacts;
contact_book() : m_book_name(), m_contacts() {}
contact_book(const name& n, const std::vector<contact>& c) : m_book_name(n), m_contacts(c) {}
};
}
@ -319,6 +328,8 @@ namespace udt
struct legacy_type
{
std::string number;
legacy_type() : number() {}
legacy_type(const std::string& n) : number(n) {}
};
}
@ -593,6 +604,8 @@ struct small_pod
struct non_pod
{
std::string s;
non_pod() : s() {}
non_pod(const std::string& S) : s(S) {}
};
template <typename BasicJsonType>