tweak SFINAE checks for internal types (see commit body)

only check for public types (iterators, json_pointer)

for private ones (m_array.iterator, primitive_iterator) simply double
parentheses on relevant Catch checks
This commit is contained in:
Théo DELRIEU 2017-01-08 18:17:33 +01:00
parent 317883b21b
commit be6b417c87
4 changed files with 146 additions and 154 deletions

View file

@ -469,14 +469,13 @@ struct is_compatible_float_type
std::is_floating_point<CompatibleFloat>::value; std::is_floating_point<CompatibleFloat>::value;
}; };
template <typename T, typename BasicJson, typename PrimitiveIterator> template <typename BasicJson, typename T>
struct is_basic_json_nested_class struct is_basic_json_nested_type
{ {
static auto constexpr value = std::is_same<T, typename BasicJson::iterator>::value or static auto constexpr value = std::is_same<T, typename BasicJson::iterator>::value or
std::is_same<T, typename BasicJson::const_iterator>::value or std::is_same<T, typename BasicJson::const_iterator>::value or
std::is_same<T, typename BasicJson::reverse_iterator>::value or std::is_same<T, typename BasicJson::reverse_iterator>::value or
std::is_same<T, typename BasicJson::const_reverse_iterator>::value or std::is_same<T, typename BasicJson::const_reverse_iterator>::value or
std::is_same<T, PrimitiveIterator>::value or
std::is_same<T, typename BasicJson::json_pointer>::value; std::is_same<T, typename BasicJson::json_pointer>::value;
}; };
@ -1844,19 +1843,16 @@ class basic_json
// constructor chosen when: // constructor chosen when:
// - JSONSerializer::to_json exists for type T // - JSONSerializer::to_json exists for type T
// - T is not a istream, nor convertible to basic_json (float, vectors, etc) // - T is not a istream, nor convertible to basic_json (float, vectors, etc)
template < template <typename T, typename U = uncvref_t<T>,
typename T, enable_if_t<
enable_if_t<not std::is_base_of<std::istream, uncvref_t<T>>::value and not std::is_base_of<std::istream, U>::value and
not detail::is_basic_json_nested_class<uncvref_t<T>, basic_json_t, primitive_iterator_t>::value and not std::is_same<U, basic_json_t>::value and
not std::is_same<uncvref_t<T>, basic_json_t>::value and not detail::is_basic_json_nested_type<basic_json_t,U>::value and
not std::is_same<uncvref_t<T>, typename basic_json_t::array_t::iterator>::value and detail::has_to_json<JSONSerializer, basic_json, U>::value,
not std::is_same<uncvref_t<T>, typename basic_json_t::object_t::iterator>::value and int> = 0>
detail::has_to_json<JSONSerializer, basic_json, basic_json(T &&val)
uncvref_t<T>>::value,
int> = 0 >
basic_json(T && val)
{ {
JSONSerializer<uncvref_t<T>>::to_json(*this, std::forward<T>(val)); JSONSerializer<uncvref_t<T>>::to_json(*this, std::forward<T>(val));
} }
/*! /*!

View file

@ -469,14 +469,13 @@ struct is_compatible_float_type
std::is_floating_point<CompatibleFloat>::value; std::is_floating_point<CompatibleFloat>::value;
}; };
template <typename T, typename BasicJson, typename PrimitiveIterator> template <typename BasicJson, typename T>
struct is_basic_json_nested_class struct is_basic_json_nested_type
{ {
static auto constexpr value = std::is_same<T, typename BasicJson::iterator>::value or static auto constexpr value = std::is_same<T, typename BasicJson::iterator>::value or
std::is_same<T, typename BasicJson::const_iterator>::value or std::is_same<T, typename BasicJson::const_iterator>::value or
std::is_same<T, typename BasicJson::reverse_iterator>::value or std::is_same<T, typename BasicJson::reverse_iterator>::value or
std::is_same<T, typename BasicJson::const_reverse_iterator>::value or std::is_same<T, typename BasicJson::const_reverse_iterator>::value or
std::is_same<T, PrimitiveIterator>::value or
std::is_same<T, typename BasicJson::json_pointer>::value; std::is_same<T, typename BasicJson::json_pointer>::value;
}; };
@ -1844,19 +1843,16 @@ class basic_json
// constructor chosen when: // constructor chosen when:
// - JSONSerializer::to_json exists for type T // - JSONSerializer::to_json exists for type T
// - T is not a istream, nor convertible to basic_json (float, vectors, etc) // - T is not a istream, nor convertible to basic_json (float, vectors, etc)
template < template <typename T, typename U = uncvref_t<T>,
typename T, enable_if_t<
enable_if_t<not std::is_base_of<std::istream, uncvref_t<T>>::value and not std::is_base_of<std::istream, U>::value and
not detail::is_basic_json_nested_class<uncvref_t<T>, basic_json_t, primitive_iterator_t>::value and not std::is_same<U, basic_json_t>::value and
not std::is_same<uncvref_t<T>, basic_json_t>::value and not detail::is_basic_json_nested_type<basic_json_t,U>::value and
not std::is_same<uncvref_t<T>, typename basic_json_t::array_t::iterator>::value and detail::has_to_json<JSONSerializer, basic_json, U>::value,
not std::is_same<uncvref_t<T>, typename basic_json_t::object_t::iterator>::value and int> = 0>
detail::has_to_json<JSONSerializer, basic_json, basic_json(T &&val)
uncvref_t<T>>::value,
int> = 0 >
basic_json(T && val)
{ {
JSONSerializer<uncvref_t<T>>::to_json(*this, std::forward<T>(val)); JSONSerializer<uncvref_t<T>>::to_json(*this, std::forward<T>(val));
} }
/*! /*!

View file

@ -91,7 +91,7 @@ TEST_CASE("const_iterator class")
json j(json::value_t::null); json j(json::value_t::null);
json::const_iterator it(&j); json::const_iterator it(&j);
it.set_begin(); it.set_begin();
CHECK(it == j.cbegin()); CHECK((it == j.cbegin()));
} }
SECTION("object") SECTION("object")
@ -99,7 +99,7 @@ TEST_CASE("const_iterator class")
json j(json::value_t::object); json j(json::value_t::object);
json::const_iterator it(&j); json::const_iterator it(&j);
it.set_begin(); it.set_begin();
CHECK(it == j.cbegin()); CHECK((it == j.cbegin()));
} }
SECTION("array") SECTION("array")
@ -107,7 +107,7 @@ TEST_CASE("const_iterator class")
json j(json::value_t::array); json j(json::value_t::array);
json::const_iterator it(&j); json::const_iterator it(&j);
it.set_begin(); it.set_begin();
CHECK(it == j.cbegin()); CHECK((it == j.cbegin()));
} }
} }
@ -118,7 +118,7 @@ TEST_CASE("const_iterator class")
json j(json::value_t::null); json j(json::value_t::null);
json::const_iterator it(&j); json::const_iterator it(&j);
it.set_end(); it.set_end();
CHECK(it == j.cend()); CHECK((it == j.cend()));
} }
SECTION("object") SECTION("object")
@ -126,7 +126,7 @@ TEST_CASE("const_iterator class")
json j(json::value_t::object); json j(json::value_t::object);
json::const_iterator it(&j); json::const_iterator it(&j);
it.set_end(); it.set_end();
CHECK(it == j.cend()); CHECK((it == j.cend()));
} }
SECTION("array") SECTION("array")
@ -134,7 +134,7 @@ TEST_CASE("const_iterator class")
json j(json::value_t::array); json j(json::value_t::array);
json::const_iterator it(&j); json::const_iterator it(&j);
it.set_end(); it.set_end();
CHECK(it == j.cend()); CHECK((it == j.cend()));
} }
} }
} }
@ -220,7 +220,7 @@ TEST_CASE("const_iterator class")
{ {
json j(json::value_t::null); json j(json::value_t::null);
json::const_iterator it = j.cbegin(); json::const_iterator it = j.cbegin();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
it++; it++;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -229,9 +229,9 @@ TEST_CASE("const_iterator class")
{ {
json j(17); json j(17);
json::const_iterator it = j.cbegin(); json::const_iterator it = j.cbegin();
CHECK(it.m_it.primitive_iterator.m_it == 0); CHECK((it.m_it.primitive_iterator.m_it == 0));
it++; it++;
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
it++; it++;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -240,28 +240,28 @@ TEST_CASE("const_iterator class")
{ {
json j({{"foo", "bar"}}); json j({{"foo", "bar"}});
json::const_iterator it = j.cbegin(); json::const_iterator it = j.cbegin();
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
it++; it++;
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
} }
SECTION("array") SECTION("array")
{ {
json j({1, 2, 3, 4}); json j({1, 2, 3, 4});
json::const_iterator it = j.cbegin(); json::const_iterator it = j.cbegin();
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
it++; it++;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it++; it++;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it++; it++;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it++; it++;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
} }
} }
@ -271,7 +271,7 @@ TEST_CASE("const_iterator class")
{ {
json j(json::value_t::null); json j(json::value_t::null);
json::const_iterator it = j.cbegin(); json::const_iterator it = j.cbegin();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
++it; ++it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -280,9 +280,9 @@ TEST_CASE("const_iterator class")
{ {
json j(17); json j(17);
json::const_iterator it = j.cbegin(); json::const_iterator it = j.cbegin();
CHECK(it.m_it.primitive_iterator.m_it == 0); CHECK((it.m_it.primitive_iterator.m_it == 0));
++it; ++it;
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
++it; ++it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -291,28 +291,28 @@ TEST_CASE("const_iterator class")
{ {
json j({{"foo", "bar"}}); json j({{"foo", "bar"}});
json::const_iterator it = j.cbegin(); json::const_iterator it = j.cbegin();
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
++it; ++it;
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
} }
SECTION("array") SECTION("array")
{ {
json j({1, 2, 3, 4}); json j({1, 2, 3, 4});
json::const_iterator it = j.cbegin(); json::const_iterator it = j.cbegin();
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
++it; ++it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
++it; ++it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
++it; ++it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
++it; ++it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
} }
} }
@ -322,16 +322,16 @@ TEST_CASE("const_iterator class")
{ {
json j(json::value_t::null); json j(json::value_t::null);
json::const_iterator it = j.cend(); json::const_iterator it = j.cend();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
} }
SECTION("number") SECTION("number")
{ {
json j(17); json j(17);
json::const_iterator it = j.cend(); json::const_iterator it = j.cend();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
it--; it--;
CHECK(it.m_it.primitive_iterator.m_it == 0); CHECK((it.m_it.primitive_iterator.m_it == 0));
it--; it--;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -340,28 +340,28 @@ TEST_CASE("const_iterator class")
{ {
json j({{"foo", "bar"}}); json j({{"foo", "bar"}});
json::const_iterator it = j.cend(); json::const_iterator it = j.cend();
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
it--; it--;
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
} }
SECTION("array") SECTION("array")
{ {
json j({1, 2, 3, 4}); json j({1, 2, 3, 4});
json::const_iterator it = j.cend(); json::const_iterator it = j.cend();
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
it--; it--;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it--; it--;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it--; it--;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it--; it--;
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
} }
} }
@ -371,16 +371,16 @@ TEST_CASE("const_iterator class")
{ {
json j(json::value_t::null); json j(json::value_t::null);
json::const_iterator it = j.cend(); json::const_iterator it = j.cend();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
} }
SECTION("number") SECTION("number")
{ {
json j(17); json j(17);
json::const_iterator it = j.cend(); json::const_iterator it = j.cend();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
--it; --it;
CHECK(it.m_it.primitive_iterator.m_it == 0); CHECK((it.m_it.primitive_iterator.m_it == 0));
--it; --it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -389,28 +389,28 @@ TEST_CASE("const_iterator class")
{ {
json j({{"foo", "bar"}}); json j({{"foo", "bar"}});
json::const_iterator it = j.cend(); json::const_iterator it = j.cend();
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
--it; --it;
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
} }
SECTION("array") SECTION("array")
{ {
json j({1, 2, 3, 4}); json j({1, 2, 3, 4});
json::const_iterator it = j.cend(); json::const_iterator it = j.cend();
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
--it; --it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
--it; --it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
--it; --it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
--it; --it;
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
} }
} }
} }

View file

@ -75,7 +75,7 @@ TEST_CASE("iterator class")
json j(json::value_t::null); json j(json::value_t::null);
json::iterator it(&j); json::iterator it(&j);
it.set_begin(); it.set_begin();
CHECK(it == j.begin()); CHECK((it == j.begin()));
} }
SECTION("object") SECTION("object")
@ -83,7 +83,7 @@ TEST_CASE("iterator class")
json j(json::value_t::object); json j(json::value_t::object);
json::iterator it(&j); json::iterator it(&j);
it.set_begin(); it.set_begin();
CHECK(it == j.begin()); CHECK((it == j.begin()));
} }
SECTION("array") SECTION("array")
@ -91,7 +91,7 @@ TEST_CASE("iterator class")
json j(json::value_t::array); json j(json::value_t::array);
json::iterator it(&j); json::iterator it(&j);
it.set_begin(); it.set_begin();
CHECK(it == j.begin()); CHECK((it == j.begin()));
} }
} }
@ -102,7 +102,7 @@ TEST_CASE("iterator class")
json j(json::value_t::null); json j(json::value_t::null);
json::iterator it(&j); json::iterator it(&j);
it.set_end(); it.set_end();
CHECK(it == j.end()); CHECK((it == j.end()));
} }
SECTION("object") SECTION("object")
@ -110,7 +110,7 @@ TEST_CASE("iterator class")
json j(json::value_t::object); json j(json::value_t::object);
json::iterator it(&j); json::iterator it(&j);
it.set_end(); it.set_end();
CHECK(it == j.end()); CHECK((it == j.end()));
} }
SECTION("array") SECTION("array")
@ -118,7 +118,7 @@ TEST_CASE("iterator class")
json j(json::value_t::array); json j(json::value_t::array);
json::iterator it(&j); json::iterator it(&j);
it.set_end(); it.set_end();
CHECK(it == j.end()); CHECK((it == j.end()));
} }
} }
} }
@ -204,7 +204,7 @@ TEST_CASE("iterator class")
{ {
json j(json::value_t::null); json j(json::value_t::null);
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
it++; it++;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -213,9 +213,9 @@ TEST_CASE("iterator class")
{ {
json j(17); json j(17);
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK(it.m_it.primitive_iterator.m_it == 0); CHECK((it.m_it.primitive_iterator.m_it == 0));
it++; it++;
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
it++; it++;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -224,28 +224,28 @@ TEST_CASE("iterator class")
{ {
json j({{"foo", "bar"}}); json j({{"foo", "bar"}});
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
it++; it++;
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
} }
SECTION("array") SECTION("array")
{ {
json j({1, 2, 3, 4}); json j({1, 2, 3, 4});
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
it++; it++;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it++; it++;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it++; it++;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it++; it++;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
} }
} }
@ -255,7 +255,7 @@ TEST_CASE("iterator class")
{ {
json j(json::value_t::null); json j(json::value_t::null);
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
++it; ++it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -264,9 +264,9 @@ TEST_CASE("iterator class")
{ {
json j(17); json j(17);
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK(it.m_it.primitive_iterator.m_it == 0); CHECK((it.m_it.primitive_iterator.m_it == 0));
++it; ++it;
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
++it; ++it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -275,28 +275,28 @@ TEST_CASE("iterator class")
{ {
json j({{"foo", "bar"}}); json j({{"foo", "bar"}});
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
++it; ++it;
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
} }
SECTION("array") SECTION("array")
{ {
json j({1, 2, 3, 4}); json j({1, 2, 3, 4});
json::iterator it = j.begin(); json::iterator it = j.begin();
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
++it; ++it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
++it; ++it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
++it; ++it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
++it; ++it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
} }
} }
@ -306,16 +306,16 @@ TEST_CASE("iterator class")
{ {
json j(json::value_t::null); json j(json::value_t::null);
json::iterator it = j.end(); json::iterator it = j.end();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
} }
SECTION("number") SECTION("number")
{ {
json j(17); json j(17);
json::iterator it = j.end(); json::iterator it = j.end();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
it--; it--;
CHECK(it.m_it.primitive_iterator.m_it == 0); CHECK((it.m_it.primitive_iterator.m_it == 0));
it--; it--;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -324,28 +324,28 @@ TEST_CASE("iterator class")
{ {
json j({{"foo", "bar"}}); json j({{"foo", "bar"}});
json::iterator it = j.end(); json::iterator it = j.end();
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
it--; it--;
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
} }
SECTION("array") SECTION("array")
{ {
json j({1, 2, 3, 4}); json j({1, 2, 3, 4});
json::iterator it = j.end(); json::iterator it = j.end();
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
it--; it--;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it--; it--;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it--; it--;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
it--; it--;
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
} }
} }
@ -355,16 +355,16 @@ TEST_CASE("iterator class")
{ {
json j(json::value_t::null); json j(json::value_t::null);
json::iterator it = j.end(); json::iterator it = j.end();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
} }
SECTION("number") SECTION("number")
{ {
json j(17); json j(17);
json::iterator it = j.end(); json::iterator it = j.end();
CHECK(it.m_it.primitive_iterator.m_it == 1); CHECK((it.m_it.primitive_iterator.m_it == 1));
--it; --it;
CHECK(it.m_it.primitive_iterator.m_it == 0); CHECK((it.m_it.primitive_iterator.m_it == 0));
--it; --it;
CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1)); CHECK((it.m_it.primitive_iterator.m_it != 0 and it.m_it.primitive_iterator.m_it != 1));
} }
@ -373,28 +373,28 @@ TEST_CASE("iterator class")
{ {
json j({{"foo", "bar"}}); json j({{"foo", "bar"}});
json::iterator it = j.end(); json::iterator it = j.end();
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->end()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->end()));
--it; --it;
CHECK(it.m_it.object_iterator == it.m_object->m_value.object->begin()); CHECK((it.m_it.object_iterator == it.m_object->m_value.object->begin()));
} }
SECTION("array") SECTION("array")
{ {
json j({1, 2, 3, 4}); json j({1, 2, 3, 4});
json::iterator it = j.end(); json::iterator it = j.end();
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->end()));
--it; --it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
--it; --it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
--it; --it;
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
--it; --it;
CHECK(it.m_it.array_iterator == it.m_object->m_value.array->begin()); CHECK((it.m_it.array_iterator == it.m_object->m_value.array->begin()));
CHECK(it.m_it.array_iterator != it.m_object->m_value.array->end()); CHECK((it.m_it.array_iterator != it.m_object->m_value.array->end()));
} }
} }
} }